error: expected constructor, destructor, or type conversion before '&' token
I am getting the above error when ever i try to write somethin in my cpp file.. if I have the same code inlined in my header file it compiles and works fine.. I am using the g++ compiler for compilation.. Is there any thin particular i need to look for to fix that error
Re: error: expected constructor, destructor, or type conversion before '&' token
It would be helpful if we could see the code.
Re: error: expected constructor, destructor, or type conversion before '&' token
Quote:
Originally Posted by
sundar0206
I am getting the above error when ever i try to write somethin in my cpp file.. if I have the same code inlined in my header file it compiles and works fine.. I am using the g++ compiler for compilation.. Is there any thin particular i need to look for to fix that error
Ah, that´s pretty easy to fix :D
Re: error: expected constructor, destructor, or type conversion before '&' token
Ya its a huge file dunno if you guys would need to see the whole file.... But ya one part of the code is this
Code:
Quat& operator *= (const Quat& q){
setValue(
m_w*q.get4d_X() + m_x*q.get4d_W() + m_y*q.get4d_Z() - m_z*q.get4d_Y(),
m_w*q.get4d_Y() - m_x*q.get4d_Z() + m_y*q.get4d_W() + m_z*q.get4d_X(),
m_w*q.get4d_Z() + m_x*q.get4d_Y() - m_y*q.get4d_X() + m_z*q.get4d_W(),
m_w*q.get4d_W() - m_x*q.get4d_X() - m_y*q.get4d_Y() - m_z*q.get4d_Z()
);
return *this;
}
this above code works fine when i have it in the header file .. But when i do this in the cpp file
Code:
//header file
Quat& operator *= (const Quat& q);
//cppfile
Quat& Quat::operator *= (const Quat& q){
setValue(
m_w*q.get4d_X() + m_x*q.get4d_W() + m_y*q.get4d_Z() - m_z*q.get4d_Y(),
m_w*q.get4d_Y() - m_x*q.get4d_Z() + m_y*q.get4d_W() + m_z*q.get4d_X(),
m_w*q.get4d_Z() + m_x*q.get4d_Y() - m_y*q.get4d_X() + m_z*q.get4d_W(),
m_w*q.get4d_W() - m_x*q.get4d_X() - m_y*q.get4d_Y() - m_z*q.get4d_Z()
);
return *this;
}
it throws me the error.. I can show u the file if u need it.. but I think this is a very obvious thing which I seem to miss .. I am not sure!!!
Re: error: expected constructor, destructor, or type conversion before '&' token
Quat is actually a class template, is it not?
Re: error: expected constructor, destructor, or type conversion before '&' token
Please post the minimal code that reproduces the error.
I have no problems compiling these two files:
Header file:
Code:
#ifndef QuatH
#define QuatH
class Quat
{
public:
Quat();
Quat& operator*=( const Quat& lhs );
};
#endif
Implementation file:
Code:
#include "quat.h"
Quat::Quat()
{
}
Quat& Quat::operator*=( const Quat& lhs )
{
return *this;
}
Remove snippets of your code until it compiles and then reinsert the cut parts and try to locate the error.
Re: error: expected constructor, destructor, or type conversion before '&' token
Quote:
Originally Posted by
sundar0206
Ya its a huge file dunno if you guys would need to see the whole file....
If the compiler needs the entire file to generate the error, then we need the same thing the compiler is seeing.
Quote:
But ya one part of the code is this
Just posting a piece of a file isn't going to work, since we have no idea what Qant is, whether it was defined, whether that code is in a function block, nothing.
Compiler errors are to be diagnosed by providing the smallest, but complete example that duplicates the error. This means we can copy the code right out of the message, and without editing the code, compile it to see the error.
The reason for this is simple -- by not providing this code, we have to either
1) come up with our own examples to show you that our example works (look at GNiewerth's post), or
2) we try to come up with an example that has the exact same error you have by adding or removing code. This wastes time on the people attempting to help.
The easiest thing to do is for you to diagnose this yourself by coming up with a small complete example. Not only will the example be complete, maybe by creating a smaller example, you'll find the error yourself.
Regards,
Paul McKenzie
Re: error: expected constructor, destructor, or type conversion before '&' token
Thanks guys...
Will have a look at creating a smaller version of the code.... and try posting it in a bit if I still have the problem