Skip to content

Instantly share code, notes, and snippets.

@nponeccop
Created July 26, 2015 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nponeccop/c3138d106d18448d343d to your computer and use it in GitHub Desktop.
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
#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