template<class T,class U>
class A {}; // primary
class B;
template<typename T>
class C;
namespace N
{
template<class T>
class A<T,T>
{
public:
int x;
A(int x_):x(x_){}
void print()
{
std::cout << x << std::endl;
}
};
class B
{
};
template<typename T>
class C{};
}
int main(int argc, char* argv[])
{
A<int, int> a(2); //ok
a.print(); //2,partial template specialization in namespace is visible
//partial template specialization is visible ,despite in namespace N
B b; //error incomplete type is not allowed
C<int> c; //error incomplete type is not allowed
}
//another example
template<class T,class U>
class A {}; // primary
namespace N
{
class B
{
template<class T>
friend class A<T, T>;
};
template<class T>
class A<T, T>
{
};
class C
{
template<class T>
friend class A<T, int>;
};
template<class T>
class A<T, int>
{
}
}
//A<int,int> shoude be class B friend or class C friend?