was reading book with solving different problems. And got next thing. There was a question, on how to check if class is derived from another one, using templates. And there was example on how to do this at compile time. I'm wodering why this code dont need definitions of static function.
template<typename T, typename B>
class CIsDerived
{
private:
class CIsValid
{
};
class CIsInValid
{
int sizeExp[3];
};
static CIsValid Check(B * pBaseClass);
static CIsInValid Check(...);
public:
enum
{
Is = sizeof(CIsValid) == sizeof(Check(static_cast<T*>(0)))
};
};
class CBase
{
public:
};
class CDerv : public CBase
{
public:
};
void main()
{
cout << CIsDerived<CDerv, CBase>::Is << endl;
cout << CIsDerived<string, CBase>::Is << endl;
}
Can someone provide any book, were this thing is explained in depth?