C++ template copy constructor on template class

前端 未结 3 661
半阙折子戏
半阙折子戏 2020-11-29 13:13

I have a template class that has a template copy constructor. The problem is when I instantiate this class using another instance of this class with the same template type,

3条回答
  •  清歌不尽
    2020-11-29 13:53

    When you do not have a copy constructor in you code, the compiler will implicitly generate it. Therefore when this line is executed:

    MyTemplateClass instance2(instance);
    

    A copy constructor is being executed, though obviously not yours. I think that templating has nothing to do with it.

    Read more about it here: Implicitly-defined copy constructor

提交回复
热议问题