#include <iostream>
using namespace std;
template<class T, int I> // primary template
struct A {
void f(); // member declaration
};
template<class T, int I>
void A<T,I>::f() { } // primary template member definition
// partial specialization
template<class T>
struct A<T,2> {
void f();
void g();
void h();
};
// member of partial specialization
template<class T>
void A<T,2>::g() {
cout << "partial g()" << endl;
}
template<class T>
void A<T,2>::h() {
cout << "partial h()" << endl;
}
// explicit (full) specialization
// of a member of partial specialization
template<>
void A<char,2>::h() {
cout << "explicit h()" << endl;
}
int main() {
A<char,2> a2;
a2.f(); // ERROR, partial can not access primary member
a2.g(); // OK, uses partial specialization's member definition
a2.h(); // OK, explicit h() being called.
}
I went thorugh cpp reference, It says
"Members of partial specializations are not related to the members of the primary template."
So understandably, a2 can not access member of primary specialization a2.f()
?
My Questions are
how is the relationship between member of partial specialization and member of explicit specialization ?
Why a2 can access the member of partial specialization
a2.g()
here ?