#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