How can a derived C++ class clone itself via a base pointer?

后端 未结 6 740
旧巷少年郎
旧巷少年郎 2021-01-13 09:34

Here\'s what I\'m trying to do (this code doesn\'t work):

class Base
{
    virtual Base *clone() { return new Base(this); }
    virtual void ID() { printf(\"         


        
6条回答
  •  难免孤独
    2021-01-13 10:08

    The code looks fine, other than the silly syntax typos and the missing ctors.

提交回复
热议问题