codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include <iostream> #include <algorithm> using std::cout; using std::endl; class Base { public: Base(int para) { a = para; cout << "Base::a = " << a << endl; } private: int a; }; class Derive : public Base { public: int foo() { cout << "Derived::foo() return 0" << endl; return 0; } Derive() : Base(foo()) {} }; class Derive2 : public Base { public: int foo() { cout << "Derive2::foo() return " << b << endl; return b; } Derive2() : Base(foo()),b(0) {} private: int b; }; int main(void) { char buf[sizeof(Derive)+sizeof(Derive2)]; std::fill(buf, buf + sizeof(buf), -1); Derive* cld = new(buf) Derive(); Derive2* cld2 = new(buf + sizeof(Derive))Derive2(); cld->~Derive(); cld2->~Derive2(); return 0; }
Private
[
?
]
Run code
Submit