#include <iostream>
#include <vector>
using namespace std;
class Node
{
public:
static Node* create();
void autorelease();
protected:
Node();
virtual bool init();
virtual ~Node();
};
void Node::autorelease()
{
delete this;
}
Node* Node::create()
{
auto sp = new Node();
if(sp && sp->init())
{
}
else
{
delete sp;
}
return sp;
}
Node::Node()
{
}
Node::~Node()
{
cout << "the Node is destructed" << endl;
}
bool Node::init()
{
return true;
}
class Player : public Node
{
public:
static Player* create();
protected:
Player();
virtual ~Player();
virtual bool init();
};
Player::Player()
{
}
Player::~Player()
{
cout << "the player is destructed" << endl;
}
Player* Player::create()
{
auto sp = new Player();
if(sp && sp->init())
{
}
else
{
delete sp;
}
return sp;
}
bool Player::init()
{
return true;
}
int main()
{
auto sp = Player::create();
sp->autorelease();
return 0;
}
结果输出:
the player is destructed
the Node is destructed
Program ended with exit code: 0
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。