Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy Constructor Problems 1

Status
Not open for further replies.

Kalisto

Programmer
Feb 18, 2003
997
GB
I have been using c# fo rth elast few months, and have come back to c++ for research purposes.

I have 2 problems, both of which are irritatingly stupid, so apologies in advance.

1) I have closed down my files in project window, and cannot remmeber the key code or menu option to bring it back. Can anyone remind me?

2) code is below, I can see nothing wrong with the declaration, or implementation, but when I compile I get 2 errors. Removing these files removes the errors, so the problem has to be in there somewhere. Cna anyone see what Im doing wrong?

.h

Code:
#pragma once
#include <string>

class _Chromosome
{
public:
	//Constructor / Destructors
	_Chromosome(void);
	_Chromosome(const _Chromosome &T);
	virtual ~_Chromosome(void);

private:
	std::string baseFName;	//FileName
	float fVersion;	//Version of the code
	int nBeamNum;
	int nRows;
	int nCols;
	float rTheta;
	float rPhi;

};

.cpp
Code:
#include "StdAfx.h"
#include ".\_Chromosome.h"

_Chromosome::_Chromosome(void)
{
	//Get the Root File Path and Name for this Object
	//As this is the Class For the Header of Each Air File, 
	//The Type of File for get_optfile() is 9
//	get_optfile(9,1,&BaseFName.c_str());

	//Temporary Code
	baseFName = "d:/data/inair.";
	fVersion = 0.1f;

}

/*
Overloaded Constructor Used for Creating a copy of an Existing Class

*/

_Chromosome::_Chromosome(const _Chromsome& T)
{
	nBeamNum = T.nBeamNum;
	nRows = T.nRows;
	nCols = T.nCols;
	rTheta = T.rTheta;
	rPhi = T.rPhi;
}

_Chromosome::~_Chromosome(void)
{
}

The errors are;
C2143 - missing , before &
C2511 - _Chromosome::_Chromosome(const int) no overloaded member funciton found in _Chromosome

this is slowly driving me doolally, so any help to spot what is wrong will be appreciated

Thanks
K
 
1) Alt+0 (zero)

2) Note giving stuff names starting with and underscore is considered bad practice, as that is usually used for internal C++ stuff.

Along with errors you usually get information on what file & line the errors occur. Any reason you dont reveal that to us?

>C2511 - _Chromosome::_Chromosome(const int) no overloaded member funciton found in _Chromosome

How do you try to instantiate the class?

/Per

&quot;It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure.&quot;
 
Hi Per, thank sofr the reply
Alt 0 Didnt work, but this machine is misbehaiving it's self, so I'll try that again after a reboot

I know I shoulkdnt use underscore, but I have a full copy of my chromosome class, that was giving me the errors, and so I created a smaller model to eliminate the issues, the underscores will be replaced with the original as soon as I fix the problem, they remind me that this is a scaled down temporary class.

The errors occur in the _Chromosome.cpp class, and they occur on the line where the copy constructor is defined in the cpp file.

I have tried instantiating the class using both the below methods

_Chromosome clsChr;
_Chromosome *ptrChr = new _Chromosome;

Neither has any effect on the compile errors, but the error is there in compile time, and again removing all declarations, but leaving hte files in the project causes me the same problem
 
Its simply a typo in the conpy contructor.

const _Chromsome& T
should be
const _Chromosome& T

/Per

&quot;It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure.&quot;
 
conpy? Oh, well...the keyboard is my enemy too...

/Per

&quot;It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure.&quot;
 
*************
I wont repeat the words I have just been using.

Lesson 1. Dont assume your spelling is right.

Thanks Per
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top