Sign in to follow this  
derek7

my god

Recommended Posts

derek7    100
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[i] = 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????

Share this post


Link to post
Share on other sites
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[i] = new CInstance1(&Terrain);


HTH,

Share this post


Link to post
Share on other sites
derek7    100

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.

Share this post


Link to post
Share on other sites
Squirm    481
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.

Share this post


Link to post
Share on other sites
derek7    100
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[i] = 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[i] = new CInstance1;



Share this post


Link to post
Share on other sites
Fruny    1658
Quote:
m_instance[i] = 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.

Share this post


Link to post
Share on other sites
derek7    100
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?

Share this post


Link to post
Share on other sites
Squirm    481
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() {}

Share this post


Link to post
Share on other sites
derek7    100
Quote:
Original post by Fruny
Quote:
m_instance[i] = 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.

Share this post


Link to post
Share on other sites
Sandman    2210
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.

Share this post


Link to post
Share on other sites
derek7    100


class CInstance1
{
public:
// constructor declaration

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;
};


//constructor definition


CInstance1::CInstance1(CTerrain *terrain =0, float scale = 30, float adjust =2,float speed = 20)
{
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);
}


but when I do this:

//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[i] = new CInstance1;



compiler said no default constructor available.
but default constructor is there.

CInstance1::CInstance1(CTerrain *terrain =0, float scale = 30, float adjust =2,float speed = 20) is not default constructor???????


Share this post


Link to post
Share on other sites
derek7    100
Quote:
Original post by Sandman
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 will create C2572 error.

Share this post


Link to post
Share on other sites
Sandman    2210
Quote:
Original post by derek7
compiler said no default constructor available.
but default constructor is there.

CInstance1::CInstance1(CTerrain *terrain =0, float scale = 30, float adjust =2,float speed = 20) is not default constructor???????


It would be if the default values were in the header. As it is, the compiler isn't aware of them outside the cpp that they currently reside in.

Quote:
Original post by derek7
this will create C2572 error.


Stick them in the header, remove them from the cpp.

Share this post


Link to post
Share on other sites
garyfletcher    250
shouldn't the declaration be:

CInstance1(CTerrain *terrain , float scale = 30, float adjust =2,float speed = 20)

and the definition be:

CInstance1(CTerrain *terrain , float scale, float adjust ,float speed)
{
// code here
}

The defaults shouldn't be in the definition?

EDIT: Ah...sandman just said the same..:)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this