вторник, 24 марта 2015 г.

Проверить, является ли тип абстрактным

#include <iostream>
using namespace std;

template <class T>
class is_abstr {

typedef char yes[1];
typedef char no[2];

template <class C> static no& test(C (*)[1]);
template <class> static yes& test(...);
   
public:   
    static const bool value = sizeof(test<T>(0 )) == sizeof(yes);

};

class A {
public:
    virtual int foo() = 0;
   
};

class B : public A {
public:
    int foo() {cout << "foo";}

};


int main() {
    cout.setf(ios::boolalpha);
    cout << is_abstr<B>::value;
    return 0;
}