views:

46

answers:

2

it doesn't work for me.
i have a header file and a cpp file.
need to define a conversion operator from my class to INT, but it gives me "syntax error" when declaring it in the H file and implementing in the cpp file. maybe i got the syntax wrong? in the H file i have in "public":

operator int();

and in the cpp file i have:

A::operator int() { return mNumber ;}

if i implement the function in the H file it works, but i don't want to do that.
can anyone help?

A: 

Why don't you want to implement it in the header file? IIRC that allows the compiler to inline the function, thus removing an useless function call and possibly making the code slightly faster.

esalaka
A: 

Did you perhaps forget to include the h file in the cpp file? Sometimes shit like this happens... but it would really help to know what error you're getting

humbagumba