#include "stdafx.h"
#include <iostream>
using std::cout;
template<class T>
class IsPolymorphic
{
template<class T>
struct Check
{
enum {value = false};
};
template<class T>
struct Check<T*>
{
enum {value = true};
};
public:
enum {value = Check<T>::value};
};
template<bool flag, class T, class U>
struct Select
{
typedef T value_type;
};
template<class T, class U>
struct Select<true,T,U>
{
typedef U value_type;
};
template<class T, bool isPoly = IsPolymorphic<T>>
class Container
{
public:
typedef typename Select<isPoly,T,T*>::value_type value_type;
Container(){}
};
int _tmain(int argc, _TCHAR* argv[])
{
//cout << IsPolymorphic<int*>::value;
Container<int> c;
return 0;
}
I'm getting following errors:
Error 3 error C2512: 'Container' : no appropriate default constructor available
Error 2 error C2133: 'c' : unknown size
Error 1 error C2975: 'Container' : invalid template argument for 'isPoly', expected compile-time constant expression
As for these errors:
no 3 - clearly there is dflt ctor - so what's going on?
no 2 - why is it unknown size? I've specified int as a type so why would it be unknown?
no 1 - exactly as no 2
Thanks for any help with this.
Thanks to all of you for helping me in solving this problem