55 lines
653 B
C++
55 lines
653 B
C++
|
#include <iostream>
|
||
|
#include <cstring>
|
||
|
#include <cstdlib>
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
class A
|
||
|
{
|
||
|
public:
|
||
|
int x;
|
||
|
|
||
|
private:
|
||
|
int y;
|
||
|
|
||
|
public:
|
||
|
A(int x, int y)
|
||
|
// A()
|
||
|
{
|
||
|
cout << "A(int x,int y)" << endl;
|
||
|
// cout << "A()" << endl;
|
||
|
}
|
||
|
~A()
|
||
|
{
|
||
|
cout << "~A()" << endl;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
class B : public A
|
||
|
{
|
||
|
private:
|
||
|
int y;
|
||
|
|
||
|
public:
|
||
|
B() : A(1, 2)
|
||
|
{
|
||
|
cout << "B()" << endl;
|
||
|
}
|
||
|
~B()
|
||
|
{
|
||
|
cout << "~B()" << endl;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
cout << "A size is " << sizeof(A) << endl;
|
||
|
cout << "B size is " << sizeof(B) << endl;
|
||
|
|
||
|
B b1; // A() B() ~B() ~A()
|
||
|
|
||
|
// A a;
|
||
|
|
||
|
return 0;
|
||
|
}
|