的我有這樣一個類:檢查模板參數等於基類另一個模板參數
template <class T1, class T2>
class A
{
//Error if Base class of T2 is not T1 (At compile time)
};
我要檢查,如果T1
是基類的T2
。編譯時可以嗎?
一些例子:
class C{};
class B :public C{};
A< C, B > a; //Ok because C is base class of B
A<B, C> b; //Error B is not base class of C
A<char, char> c; //Error char is not base class of char
//.....
http://en.cppreference.com/w/cpp/types/is_base_of + http://en.cppreference.com/w/ cpp/language/static_assert –