If we have a standard class:
class Foo {
public:
int fooVar = 10;
int getFooVar();
}
The implementation for getFooVar()
would be:
int Foo::getFooVar() {
return fooVar;
}
But in a templated class:
template <class T>
class Bar {
public:
int barVar = 10;
int getBarVar();
}
The implementation for getBarVar()
must be:
template <class T>
int Bar<T>::getBarVar(){
return barVar();
}
Why must we have the template <class T>
line before the function implementation of getBarVar
and Bar<T>::
(as opposed to just Bar::), considering the fact that the function doesn't use any templated variables?
You need it because Bar
is not a class, it's a template. Bar<T>
is the 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