#include <iostream>
using namespace std;
class A
{
public:
int _a;
A()
{
_a=1;
printf("A construct\n");
}
void print()
{
printf("%d,",_a);
}
};
class B:public A
{
public:
int _a;
B()
{
_a = 2;
printf("B construct\n");
}
};
int main()
{
B b;
b.print();
printf("%d",b._a);
}
程序输出是
A construct
B construct
1,2
本文出自 “天才鸟蛋” 博客,请务必保留此出处http://curley.blog.51cto.com/1627940/1297701