作业一、将对象树模型手动实现一遍
作业二、将信号与槽函数的代码手动实现一遍
作业一
#include <iostream>
#include<list>
class Obj;
using namespace std;
typedef list<Obj*> ChildList;
class Obj
{
public:
ChildList childen;//存放子对象的链表
Obj(Obj *parent=nullptr){
if(parent!=nullptr)
{
parent->childen.push_back(this);
}
}
virtual ~Obj(){
//将所有子对象释放空间
for (auto it=childen.begin();it!=childen.end();it++) {
delete *it;
}
}
};
//定义子类
class A:public Obj
{
public:
A(Obj *parent=nullptr){
if(parent!=nullptr)
{
parent->childen.push_back(this);
}
cout<<"A::construct"<<endl;
}
~A(){
cout<<"A::xigou"<<endl;
}
};
class B:public Obj
{
public:
B(Obj *parent=nullptr){
if(parent!=nullptr)
{
parent->childen.push_back(this);
}
cout<<"B::construct"<<endl;
}
~B(){
cout<<"B::xigou"<<endl;
}
};
int main()
{
A a;
B *b=new B(&a);
return 0;
}
作业二: