Copy constructor of template class

后端 未结 2 2213
孤独总比滥情好
孤独总比滥情好 2020-11-28 09:46

I read that template copy-con is never default copy onstructor, and template assignment-op is never a copy assignment operator.

I couldn\'t understand why this res

2条回答
  •  醉酒成梦
    2020-11-28 09:51

    I can't comment on why this is how it is, but here's how you write a copy constructor and assignment operator for a class template:

        template 
        class A
        {
          public:
            A(const A &){}
            A & operator=(const A& a){return *this;}
        };
    

    and that's it.
    The trick here is that even though A is a template, when you refer to it inside the class as A (such as in the function signatures) it is treated as the full type A.

提交回复
热议问题