my god

Started by
12 comments, last by garyfletcher 18 years, 10 months ago
what the hell matter

CInstance1::CInstance1(CTerrain *terrain , float scale = 30, float adjust =2,float speed = 20)
{
	init(terrain, scale, adjust, speed);
}
void CInstance1::init(CTerrain *terrain, float scale, float adjust, float speed)
{
	m_factor = rand()*1.0f/RAND_MAX;
	m_speed = speed;
	m_scale = scale;
	m_adjust = adjust;
	m_terrain = terrain;
	
	// ¶¨Î»
	m_placeVec = D3DXVECTOR3(m_factor*m_scale, 0, m_factor*m_scale/m_adjust);
	D3DXMatrixTranslation(&m_placeMatr, m_placeVec.x, 0, m_placeVec.z);
}


// .............

m_instance = new CInstance1*[m_numInstance];
	for (int i=0;i<m_numInstance;i++)
		m_instance = new CInstance1(Terrain);


when compile it say: error C2664: ¡°CInstance1::CInstance1(const CInstance1 &)¡± : can not convert¡°CTerrain *¡±to¡°const CInstance1 &¡±. but where is CInstance1 &¡±??? where????
Advertisement
Hi Derek7

I believe you are feeding the constructor of CInstance1 with a Terrain when you should feed it with a Terrain *.

It should be
m_instance = new CInstance1*[m_numInstance];	for (int i=0;i<m_numInstance;i++)		m_instance = new CInstance1(&Terrain);


HTH,
class CInstance1{public:	CInstance1(CTerrain *terrain, float scale, float adjust, float speed);	D3DXMATRIX currMatrix(float timeDelta);private:	D3DXMATRIX   m_upMatrix;	D3DXVECTOR3  m_VecOnTerrain;	D3DXMATRIX   m_placeMatr;	D3DXVECTOR3	 m_placeVec;	D3DXMATRIX   m_goMatrix;	D3DXVECTOR3	 m_goVector;	D3DXVECTOR3	 m_direction;	float		 m_factor;	float		 m_scale;	float		 m_adjust;	float		 m_speed;	SkinnedMesh* m_mesh;	CTerrain*    m_terrain;};

here is definition.

when I do this
CInstance1::CInstance1(CTerrain *terrain =0, float scale = 30, float adjust =2,float speed = 20)
{
...
}
it say no default constructor.my god default constructor here.
new CInstance1(Terrain);

but you havent defined a CInstance1 constructor which only takes 1 parameter, so it has assumed you meant the copy constructor, which it has defined for you, and which takes a const CInstance1 &.

Does your compiler really not list the matching functions for you so that you can just see this in the error message?

Uh, my compiler would also yell at me for putting default parameter values in the function definition, when they should be in the declaration . . . if you do this, then it will find the function you expected it to find.

Quote:Original post by Emmanuel Deloget
Hi Derek7

I believe you are feeding the constructor of CInstance1 with a Terrain when you should feed it with a Terrain *.

It should be
m_instance = new CInstance1*[m_numInstance];	for (int i=0;i<m_numInstance;i++)		m_instance = new CInstance1(&Terrain);


HTH,


no

take a look more detail
void SkinnedMesh::initDeviceObjects(IDirect3DDevice9* device,const std::string& inputFilename, CTerrain* Terrain, int numInstance){	m_device = device;	m_Terrain = Terrain;		//instance	m_numInstance = numInstance;	m_instanceMatr = new D3DXMATRIX[m_numInstance];	m_instance = new CInstance1*[m_numInstance];	for (int i=0;i<m_numInstance;i++)		m_instance = new CInstance1;
Quote:m_instance = new CInstance1(Terrain);

CInstance1::CInstance1(const CInstance1 &) : can not convert CTerrain to const CInstance1 &


What is Terrain?

Squirm - I think Emmanuel is right. It's a parameter type issue, not a parameter count issue: his constructor has defaulted parameters.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Quote:Original post by Squirm
new CInstance1(Terrain);

but you havent defined a CInstance1 constructor which only takes 1 parameter, so it has assumed you meant the copy constructor, which it has defined for you, and which takes a const CInstance1 &.

Does your compiler really not list the matching functions for you so that you can just see this in the error message?

Uh, my compiler would also yell at me for putting default parameter values in the function definition, when they should be in the declaration . . . if you do this, then it will find the function you expected it to find.



the default constructor is defined in class definition other than class implementation?
fruny:
Quote:Squirm - I think Emmanuel is right. It's a parameter type issue, not a parameter count issue: his constructor has defaulted parameters.


The complaint was that it couldnt pass Terrain* to a function expecting CInstance1& . . . I don't think Emmanuels answer can account for that? Also, I stand by the belief that you have to specify the default parameters in the declaration, which he hasn't done . . .

derek7:
Quote:the default constructor is defined in class definition other than class implementation?


If you don't specify any constructor atall, the compiler will create a default constructor for you, which has no parameters. If you don't specify a constructor which takes a reference to the classes own type (a copy constructor) then the compiler will generate one of these for you. In your case it will have generated the copy constructor only, and I think it thinks you are trying to call it, because it can't find an exact match for your call and that one seems closest.

- edit for clarification -
The delcaration is the bit in the class header : class whatever { whatever(); }
The definition is the bit in the body : whatever::whatever() {}
Quote:Original post by Fruny
Quote:m_instance = new CInstance1(Terrain);

CInstance1::CInstance1(const CInstance1 &) : can not convert CTerrain to const CInstance1 &


What is Terrain?

Squirm - I think Emmanuel is right. It's a parameter type issue, not a parameter count issue: his constructor has defaulted parameters.


Terrain is pointer so Emmanuel said feed &Terrain instead of Terrain.but it is already pointer.
I suspect Squirm may be right. Since the default parameters are in the cpp file, the compiler doesn't know about them when it's trying to compile the skinned mesh code. It only knows of two constructors, as defined in the header: one which always takes four parameters, and the automatically generated copy constructor which takes just one.

Stick the default parameter values in the header, and this problem should go away.

This topic is closed to new replies.

Advertisement