If you take the following example with all method implementation code inside the class definition.
Code:
template<typename T>
class A
{
public:
void SomeMethod()
{
..
}
};
then you also have the option to have it outside the class definition.
Code:
template<typename T>
class A
{
public:
void SomeMethod();
};
template<typename T>
void SomeMethod<T>::SomeMethod()
{
..
}
I've noticed that if you have the class definitions inside the class definitions the compiler (GCC, -O1 optimization used) creates a larger executable compared to when I have the methods outside the class definition. I assume this has to do with that the compiler inlines more methods. With highest optimization settings, the executables gets the same size.
The version when the method definitions are inside the class is more verbose, especially when with many template parameters since do not have repeat it all over and over.
My question if you have the methods inside the class definition, will you get penalized by excessive inlining or is the compiler still smart enough avoiding this?