Sunday, July 12, 2009

C++ inline class member functions?

When using the "inline" qualifier for class member functions, should the inline be specified in front of the function declaration, or the function definition, or both?


Also, can the definition of the function be in a separate .cpp or is it required to be in the .h file as is the case when defining templates?


Thank you for your assistance,

C++ inline class member functions?
Both. It all has to be in the header file. Because other code that will use it needs to know it's definition in order to actually put it inline (and other code will include your header, not your source file).





Here are two examples:





class A


{


inline void a();


}


inline void A::a()


{


// code for a


}





--or--





class A


{


inline void a()


{


// code for a


}


}

anemone

No comments:

Post a Comment