#include<iostream>
using namespace std;
class A
{
public:
A():count(1){}
virtual ~A(){}
virtual A * copy () const=0;
virtual void out () const=0;
protected :
int count;
};
class B :public A
{
public:
~B()
{count=count-1;out();}
virtual A*copy() const
{B *p=new B(*this);++p->count;return p;}
virtual void out() const{cout<<count<<endl;}
};
void main()
{
B b;
A*a1=&b;
a1->out();
a1=a1->copy();
a1->out();
delete a1;
}
为什么输出
1
2
1
0
苍天啊。。。
跃然一笑
婷婷同学_
相关分类