#include <iostream.h>
#include <stdlib.h>
using namespace std;
class Base{
protected:
int *access;
public:
Base(int x=0):access(new int(x)){
cout<<"Base_"<<*access<<endl;
}
virtual ~Base(){
cout<<"~Base_"<<*access<<endl;
delete access;
}
Base& operator += (const Base& base){
*(this->access) += *(base.access);
return *this;
}
};
class Child : public Base{
protected:
int *access;
public:
Child(int x = 1)
:access(new int(x+1)), Base(x+2){
*Base::access += *access;
cout<<"Child_"<<*access<<endl;
}
~Child(){
cout<<"~Child_"<<*access<<endl;
delete access;
}
};
int main()
{
Base child(2);
Child base(3);
child+=base;
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.216.80.233