#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://curely.blog.51cto.com/1627940/1297701