这是我正在尝试做的(此代码不起作用):
class Base
{
virtual Base *clone() { return new Base(this); }
virtual void ID() { printf("BASE");
};
class Derived : publc Base
{
virtual Base *clone() { return new Derived(this); }
virtual void ID() { printf("DERIVED"); }
}
.
.
Derived d;
Base *bp = &d;
Base *bp2 = bp->clone();
bp2->ID();
Run Code Online (Sandbox Code Playgroud)
什么我喜欢是看到"派生"打印出来......我得到的是"基地".我是一名长期的C程序员,并且对C++有相当的经验...但我没有取得任何进展......任何帮助都将受到赞赏.