Copy constructor needs to call a method that depends on the object, but constructor can't be virtual

后端 未结 6 665
伪装坚强ぢ
伪装坚强ぢ 2021-01-20 19:24

I have an abstract base class with two inherited classes. In both these classes I define a virtual method that is used by the constructor. Now I need to create a copy constr

6条回答
  •  深忆病人
    2021-01-20 20:08

    In a copy constructor of class T you know that the object to be copied is of class T.

    A copy constructor can not construct an object of a derived class.

    It's the derived class' copy constructor that constructs the derived part.

    So you're confused about something: the question does not make sense.

    Presenting an example might clear up what exactly the confusion is about.

    Cheers & hth.,

提交回复
热议问题