
#include <stdio.h>
#include <windows.h>

class a
{
public:
	virtual void f() = 0;
};

class b : public virtual a
{
public:
	virtual void g() = 0;
};

class c : public virtual a
{
	int n;

public:
	c()
	{ n = 0; }

	virtual void f()
	{ ++n; }
};

class d : public b, public c
{
public:
//	virtual void f()
//	{
//		c::f();
//	}

	virtual void g()
	{
		puts( "d::g()" );
	}
};

class a2
{
public:
	virtual void f() = 0;
};

class b2 : public virtual a
{
public:
	virtual void g() = 0;
};

class c2 : public a2
{
	int n;

public:
	c2()
	{ n = 0; }

	virtual void f()
	{ ++n; }
};

class d2 : public b2, public c2
{
public:
	virtual void f()
	{
		c2::f();
	}

	virtual void g()
	{
		puts( "d::g()" );
	}
};


int main(int argc, const char * argv[])
{
	const int nAmount = 1000000000;

	d o;
	d2 o2;

	int nWins1 = 0;
	int nWins2 = 0;

	//for ( ; true ; )
	{
		DWORD dwStart = GetTickCount();

		for ( register int n = nAmount; n; --n )
			o.f();
		
		DWORD dwDuration = GetTickCount() - dwStart;
		printf( "Virtual inheritence takes %dms\n", dwDuration );



		DWORD dwStart2 = GetTickCount();

		for ( register int n = nAmount; n; --n )
			o2.f();
		
		DWORD dwDuration2 = GetTickCount() - dwStart2;
		printf( "Redirection of function %dms\n", dwDuration2 );

		if ( dwDuration2 > dwDuration )
			++nWins1;
		else
			++nWins2;

		printf( "count %d : %d\n\n", nWins1, nWins2 );
	}


	return 0;
}

