Hi,
I found the examples of explicit specialization, but I have a vagueness about code:
using namespace std;
template<class T = float, int i = 5> class A
{
public:
A();
int value;
};
template<> class A<> { public: A(); };
template<> class A<double, 10> { public: A(); };
template<class T, int i> A<T, i>::A() : value(i) {
cout << "Primary template, "
<< "non-type argument is " << value << endl;
}
A<>::A() {
cout << "Explicit specialization "
<< "default arguments" << endl;
}
A<double, 10>::A() {
cout << "Explicit specialization "
<< "<double, 10>" << endl;
}
int main() {
A<int,6> x;
A<> y;
A<double, 10> z;
}
What does this line of code do?
template<class T, int i> A<T, i>::A() : value(i)
My assumption is that we are creating general definition for A().
But what baffles me is the syntax of
A():value(i)
I remember of this from inheritance tutorial where we can specify which constructor of base class will be called together with constructor of derived class.
Can anyone explain me how does this work?
Thanks!