codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include <iostream> using std::cout; using std::endl; //non-virtual dtors struct Bar { protected: void *x; ~Bar() { cout << "in Bar dtor: " << x << endl; } public: Bar(void *x) : x(x) { cout << "in Bar ctor: " << x << endl; } }; struct Baz : public Bar { Baz(void *x) : Bar(x) { cout << "in Baz ctor: " << x << endl; } protected: ~Baz() { cout << "in Baz dtor" << x << endl; } }; struct Dummy { int d; void dummy() { cout << "dummy: d" << endl; } }; template <class Base> struct Foo : public Dummy, public Base { Foo(void *z) : Base(z) {} }; typedef Foo<Bar> Foor; typedef Foo<Baz> Fooz; int main(int a, char** b) { Foor* fr = new Foor((void*)123); Fooz* fz = new Fooz((void*)456); fr->dummy(); fz->dummy(); delete fr; fr = (Foor*)fz; delete fr; cout << "after delete" << endl; return 0; }
Private
[
?
]
Run code
Submit