All code From what I’ve read, A1 & A2 are identical, but I don’t if A3 is identical to A2. I know the code will compile since all of the A classes are tmemplated.
Note: All of the class & method declarations are in a .h file.
template <typename _Ty>
class A1 {
public:
A1();
void foo() { ... }
};
template <typename _Ty>
class A2 {
public:
A2();
void foo();
};
template <typename _Ty>
inline void A2<_Ty>::foo() { ... }
template <typename _Ty>
class A3 {
public:
A3();
void foo();
};
template <typename _Ty>
void A3<_Ty>::foo() { ... } // note: No inline keyword here.
P.S. I’ve seen variants of this question on stackoverflow, but not this exact question.
Yes, it’s meaningful, but doesn’t have much effect when combined with templates.
The major effect of the
inlinekeyword is to tell the compiler that this function may appear with the same definition in multiple compilation units, so it needs to be flagged as “select-one” for the linker (so you don’t get multiple definition errors). Templates already have this feature.inlinealso is a hint to the compiler that you think the function should be inlined, but the compiler usually makes the final decision on inlining optimizations on its own.