#include <iostream>
#include <stdio.h>
using namespace std;

struct vtbltest
{
	virtual int testvirt()
	{
		return 666;
	}
};

template <class T>
struct clearable
{
	void *cleared;
	clearable():cleared(calloc(sizeof(T), 1)) {}
	
	void clear()
	{
	    *((T*)this) = *((T*)cleared);
	};
};

class test : public clearable<test>, public vtbltest
{
	public:
		int a;
};

class test2 : public clearable<test>, public vtbltest
{
	public:
		int testvirt()
		{
			return 976;
		}
		
		int a;
};

int main() {
	test _test;
	_test.a=3;
	_test.clear();
	printf("%d, %d\n", _test.a, _test.testvirt());
	
	test2 _test2;
	_test2.a=3;
	_test2.clear();
	printf("%d, %d\n", _test2.a, _test2.testvirt());

	return 0;
}
