使用深拷贝创建的对象中的指针将指向原始对象中的对象
Will pointers in a object created using deep copy point the objects in the original object
说我有这个 class:
class Entity
{
private:
std::vector<Component*> _components;
public
Entity(std::vector<Component*>);
};
我这样做:
Entity* entity= new Entity( { new Drawable(), new Transform() ... } );
Entity* clone = new Entity(*entity);
_components中的指针指向的对象会被复制吗?还是只有指针被复制到克隆?
Will the objects that the pointers in _components
point to get copied?
没有
Or are only the pointers getting copied to clone?
是的。
说我有这个 class:
class Entity
{
private:
std::vector<Component*> _components;
public
Entity(std::vector<Component*>);
};
我这样做:
Entity* entity= new Entity( { new Drawable(), new Transform() ... } );
Entity* clone = new Entity(*entity);
_components中的指针指向的对象会被复制吗?还是只有指针被复制到克隆?
Will the objects that the pointers in
_components
point to get copied?
没有
Or are only the pointers getting copied to clone?
是的。