[Cpp]
# Include <iostream>
Using namespace std;
Class Part // component class
{
Public:
Part ();
Part (int I );
~ Part ();
Private:
Int val;
};
Class Whole: public Part
{
Public:
Whole ();
Whole (int, int );
~ Whole ();
Private:
Part one;
Part two;
Int data;
};
Part: Part ()
{
Val = 0;
Cout <"The default constructor of part was called" <val <endl;
}
Part: Part (int I)
{
Val = I;
Cout <"The constructor of part was called" <val <endl;
}
Part ::~ Part ()
{
Cout <"The destructor 33 of part was called" <val <endl;
}
Whole: Whole ()
{
Data = 0;
Cout <"The default constructor of whole was called" <data <endl;
}
Whole: Whole (int p, int I, int j, int k): Part (p), two (I), one (j), data (k)
{
Cout <"The constructor of whole was called" <data <endl;
}
Whole ::~ Whole ()
{
Cout <"The destructor 33 of whole was called" <data <endl;
}
Int main ()
{
Whole w1;
Whole w2 (1, 2, 3, 4 );
Return 0;
}
# Include <iostream>
Using namespace std;
Class Part // component class
{
Public:
Part ();
Part (int I );
~ Part ();
Private:
Int val;
};
Class Whole: public Part
{
Public:
Whole ();
Whole (int, int );
~ Whole ();
Private:
Part one;
Part two;
Int data;
};
Part: Part ()
{
Val = 0;
Cout <"The default constructor of part was called" <val <endl;
}
Part: Part (int I)
{
Val = I;
Cout <"The constructor of part was called" <val <endl;
}
Part ::~ Part ()
{
Cout <"The destructor 33 of part was called" <val <endl;
}
Whole: Whole ()
{
Data = 0;
Cout <"The default constructor of whole was called" <data <endl;
}
Whole: Whole (int p, int I, int j, int k): Part (p), two (I), one (j), data (k)
{
Cout <"The constructor of whole was called" <data <endl;
}
Whole ::~ Whole ()
{
Cout <"The destructor 33 of whole was called" <data <endl;
}
Int main ()
{
Whole w1;
Whole w2 (1, 2, 3, 4 );
Return 0;
}