标签:style blog class c code ext
#include <iostream> using namespace std; class Foo { public: Foo() { cout << "Foo" << endl; } // Foo类含有默认构造函数 }; class Bar { public: Foo foo; int x; }; int main() { Bar bar; cout << bar.x; return 0; }
#include <iostream> using namespace std; class Base { public: Base() { cout << "Base" << endl; } }; class Foo { public: Foo() { cout << "Foo" << endl; } // Foo类含有默认构造函数 }; class Bar: public Base { public: Foo foo; int x; }; int main() { Bar bar; cout << bar.x; return 0; }
#include <iostream> using namespace std; class A { public: int x; }; class B: virtual public A {}; class C: virtual public A {}; class D: virtual public B, virtual public C {}; int main() { D d; B b; C c; cout << &(b.x) << endl; cout << &(c.x) << endl; cout << &(d.x) << endl; cout << &(d.B::x) << endl; cout << &(d.C::x) << endl; return 0; }
标签:style blog class c code ext
原文地址:http://blog.csdn.net/nestler/article/details/26143515