qfedu-cpp-level/day5/d6.cpp

55 lines
653 B
C++
Raw Permalink Normal View History

2023-08-14 17:20:39 +08:00
#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;
}