我想创造一个
Actor
男演员
Actor other = Actor();
Actor* ptr = &other;
然后,当我试图
delete ptr
程序exe已触发断点
但是,当我创建一个新的
而不是分配
ptr
参考
other
,我可以安全地
delete
它没有任何错误:
Actor* ptr = new Actor();
delete ptr;
我不明白问题出在哪里。
这是我的
男演员
类看起来像:
演员h:
class Actor
{
private:
unsigned id;
string name;
vector< unique_ptr< Behaviour > > allBehaviours;
public:
Actor();
virtual ~Actor();
void Init(); // Go through all the behaviors and call their Inits and Ticks
void Tick();
}
Actor.cpp:
#include "Planet.h"
#include "Behaviour.h"
#include "Actor.h"
Actor::Actor()
{
win.GetCurrentPlanet()->AddActor(this);
planet = win.GetCurrentPlanet();
}
Actor::~Actor()
{
printf("Deleted Actor!");
if (allBehaviours.size() > 0)
allBehaviours.clear();
}
// Init and Tick and some getters, setters for name and id
The Rule of Three
,但我不明白在设置这样的指针时使用了什么运算符: