#include <iostream>
#include <vector>
#include <memory>
using namespace std;

class IA
{
public:
	virtual ~IA() {}
	void A() { cout << "A" << endl; }
};
class IB
{
public:
	virtual ~IB() {}
	void B() { cout << "A" << endl; }
};
class IC
{
public:
	virtual ~IC() {}
	void C() { cout << "A" << endl; }
};

class C : IA, IB, IC
{
public:
};

void QueryInterface(int n, C* cthis, void** ptr)
{
	switch (n)
	{
	case 1:
		*ptr = reinterpret_cast<IA*>(cthis);
		break;
	case 2:
		*ptr = reinterpret_cast<IB*>(cthis);
		break;
	case 3:
		*ptr = reinterpret_cast<IC*>(cthis);
		break;
	}
}

void QueryInterface2(int n, C* cthis, void** ptr)
{
	switch (n)
	{
	case 1:
		*ptr = (IA*)cthis;
		break;
	case 2:
		*ptr = (IB*)cthis;
		break;
	case 3:
		*ptr = (IC*)cthis;
		break;
	}
}
int main() {
	IA* ptr;
	cout<<"Cpp style cast."<<endl;
	C c;
	QueryInterface(1, &c, (void**)&ptr);
	cout << ptr << endl;
	QueryInterface(2, &c, (void**)&ptr);
	cout << ptr << endl;
	QueryInterface(3, &c, (void**)&ptr);
	cout << ptr << endl;
	
	cout<<"C style cast."<<endl;
	QueryInterface2(1, &c, (void**)&ptr);
	cout << ptr << endl;
	QueryInterface2(2, &c, (void**)&ptr);
	cout << ptr << endl;
	QueryInterface2(3, &c, (void**)&ptr);
	cout << ptr << endl;

	return 0;
}