79558158

Date: 2025-04-06 11:57:43
Score: 1.5
Natty:
Report link
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?
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (1):
Posted by: 张正龙