Created
July 26, 2015 17:00
-
-
Save nponeccop/c3138d106d18448d343d to your computer and use it in GitHub Desktop.
List of subclasses without default of copy constructors with 1 allocation per node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <new> | |
template <typename T> | |
struct cons | |
{ | |
cons<T> *next; | |
char fake; | |
}; | |
class evil | |
{ | |
evil(const evil &) {}; | |
public: | |
evil(int, int) {}; | |
virtual int answer() { return 42; }; | |
}; | |
class devil : public evil | |
{ | |
int x; | |
public: | |
devil(int _x) : x(_x), evil(666,666) {}; | |
virtual int answer() { return x; }; | |
}; | |
typedef cons<evil> list; | |
list * head; | |
void addEvil() | |
{ | |
list * x = (list*)new char[sizeof(cons<evil>) - sizeof(char) + sizeof(evil)]; | |
new (&x->fake) evil(42,42); | |
x->next = head; | |
head = x; | |
} | |
void addDevil(int xx) {}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment