- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
#include <iostream>
using namespace std;
class cs{protected: int t;int fs(){return t;} cs(int p):t(p){} ~cs(){cout<<"\n~cs"<<this;} friend void sh(cs*);};
class cn:protected cs {protected: int t /* ,z */ ; cn(int p, int ps):cs(ps), t(p){} int fs(){return t+cs::fs();}};
class ct:protected cn, protected cs {protected: int t;int fs(){return t+cs::fs()+cn::fs();} friend int sm( ct* x){return x->fs();}
friend void sh(ct*);
public: ct(int p, int ps, int pns, int pn):cs(ps), t(p), cn(pn,pns){} //void setZ(int pz){z=pz;} int getZ(){return z;}
~ct(){cout<<"\n~ct";}};
void sh(ct* x){cout <<endl<<x<<' '<<x->t<<' '<<x->cs::t<<' '<<x->cn::t<<' '<<x->cn::cs::t;}
void shcs(cs* x){ cout <<endl<<x; sh(x);}
void sh(cs* x){cout <<endl<<x<<' '<<x->t;}
struct ss {int t;ss(int p):t(p){} void sh(){cout<<"\nsst="<<t;}~ss(){cout<<"\n~ss"<<this<<' '<<sizeof(*this);}};// no distructor for *this
struct sn: ss { int t; sn(int p, int ps):ss(ps), t(p){} };
struct st: sn, ss { int t; st(int p, int ps, int pns, int pn):ss(ps), t(p), sn(pn,pns){} ~st(){cout<<"\n~st"<<' '<<sizeof(*this);}};
void main()
{
ct* pct = new ct(1,2,4,8);cout <<sm(pct);
// pct->setZ(77);cout <<pct->getZ()<<endl;
for (int t= sizeof(*pct)/sizeof(int) ,sm=0, *pi=(int*)pct;t--; sm+= *pi++,cout<<' '<<sm);//4 12 14
cout<<"\ncalling shcs";sh(pct);shcs((cs*)pct);shcs((cs*)(cn*)pct);
delete pct;
st* pst = new st(1,2,4,8);
sn* psn=0;
ss* pss; cout <<"\n ss* ->t="<<(pss /* = psn */ = pst)->t<<' '<<pss<<' '<<psn<<' '<<' '<<pst; // different pss' addresses
cout <<"\n ss* ->t="<<(pss=(sn*)pst)->t<<' '<<pss<<' '<<pst;
st* ps2= (st*)pss; cout<<"\nst* ps2 = (st*) pss"<<ps2;// not existing instant on that address - CAN CRASH!!!
/* pss=pst; */ delete /*(st*)(sn*)*/ pss;//??????
system("pause");
}
Изучение бинарных деревьев. Компьютерная Академия "ШАГ" Киевский филиал