且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

复制在C ++中具有自指针的类的构造函数?

更新时间:2023-02-02 23:29:20

怎么样

if (obj.parent != NULL)
    parent = new City(*obj.parent)
else
    parent = NULL;

这应该有效,除非您在父层次结构中有循环。

This should work unless you have cycles in the parent hierarchy.