65,210
社区成员
发帖
与我相关
我的任务
分享然后
B b;
A a = b;
#include <iostream>
using namespace std;
class A
{
public:
int m;
A():m(2){cout<<"the m's address is:"<<&m<<endl;};
};
class B : public A
{
public:
int n ;
B():n(3){cout<<"the n's address is:"<<&n<<endl;};
};
int main()
{
B b;
A a = b;
system("pause");
return 0;
}
#include <iostream>
using namespace std;
class A
{
public:
int m;
A():m(2){};
};
class B : public A
{
public:
int n ;
B():n(3){};
};
int main()
{
B b;
A a = b;
cout << "a SIZE:" << sizeof(a) << endl; // a中只存放有int m, 其大小为4
cout << "b SIZE:" << sizeof(b) << endl; // b中存放有int m, int n,其大小为8
cout << "a.m: " << a.m << endl; //a中只存有int m
cout << "b.m: " << b.m << endl; //b中存有int m , int n
cout << "b.n: " << b.n << endl;
return 0;
}