I have the following template class and a (global) variable of its type:
template <typename ClassT> struct ClassTester : public ClassT { typedef ClassT type; }; ClassTester<int> *aaa;
I expect a compilation error because int cannot be obtained, but this compiles in Visual C ++ 2010.
If I delete the pointer, I get the expected compilation error (int cannot be obtained):
ClassTester<int> bbb;
I wanted to use this class to test SFINAE whether this type is a class that can be obtained from:
template <typename T> struct CanBeDerivedFrom { template <typename C> static int test(ClassTester<T> *) { } template <typename> static char test(...) { } static const bool value = (sizeof(test<T>(0)) == sizeof(int)); };
This, however, always returns true even for primitive types such as int due to the above reason. Is this the expected / acceptable behavior of C ++?
source share