Does a templated constructor override the implicit copy constructor in C++?

前端 未结 3 654
梦毁少年i
梦毁少年i 2021-01-18 05:29

Does a templated constructor (such as the following) override the implicit copy constructor?

template 
struct Foo
{
    T data;

    // ...

          


        
3条回答
  •  走了就别回头了
    2021-01-18 06:16

    Does a templated constructor (such as the following) override the implicit copy constructor?

    No. The copy constructor is still implicitly declared, and is chosen in preference to the template.

    Is there any way around this without explicitly defining a copy constructor?

    No. If you don't want the implicit copy constructor, then you'll have to define one yourself.

提交回复
热议问题