Suppose I have:
template <typename T>
class A
{
//Do something with T
};
I know that the compiler will generate a class A<T>
for each different T
defined in the code.
What if I have:
class B
{
template <typename T>
void f() { /* Do something with T */ }
};
Would there be only one definition of class B
but multiple overloads of f()
for each different T
it's called with?
Yes, with every instantiation of f<T>
there will be a definition of f()
generated by compiler.
Depending on the compiler, the f()
could be optimized due to inlining or it can just acquire that much space in the code segment.
However, I have seldom came across this kind of design where you have a non-static template member function (without any argument!) inside a non-template class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With