[ create a new paste ] login | about

Link: http://codepad.org/fEj4O3KP    [ raw code | output | fork ]

ninwa - C++, pasted on Oct 12:
#include <cstdlib>
#include <iostream>

template <typename T>
class Identifiable
{
  public:
	static const int CID;
	
	template <typename C>
	static bool instanceof(const C& c){
		if(C::CID == Identifiable<T>::CID)
			return true;
		return false;
	}
};

template <typename T>
const int Identifiable<T>::CID = rand();

class Foo : public Identifiable<Foo>
{
};

class Bar : public Identifiable<Bar>
{
};

int main()
{
	Foo a;
	Foo b;
	
	Bar c;
	
	std::cout << (Foo::instanceof(a)) << std::endl
	          << (Bar::instanceof(a)) << std::endl;
}


Output:
1
2
true
false


Create a new paste based on this one


Comments: