Why can't I override the default copy constructor and assignment operator with template versions in C++

前端 未结 2 1796
栀梦
栀梦 2020-12-11 18:07

I asked this question about overloading the copy constructor and assignment operator with template versions and considering the confusion involving around the question (sinc

2条回答
  •  南方客
    南方客 (楼主)
    2020-12-11 18:25

    template
    BaseClass(const T& a_other) 
    

    First of all, this is not a copy-constructor. It is rather a templated constructor.

    The copy-constructor should be this:

    BaseClass(const BaseClass & a_other)
    

    Notice the difference?

    Note that the templated constructor doesn't define copy-constructor. The compiler will still generate a default copy-constructor for you, instead of instantiating the templated constructor.

    Same argument for copy-assignment.

提交回复
热议问题