#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;
}
我收到以下错误另一个问题:
错误3错误C2512: '集装箱':没有适当的默认构造函数可用
错误2错误C2133: 'C':未知大小
错误1个错误C2975:“容器”:关于“isPoly”无效模板参数,预期编译时间常量表达式使用模板
至于这些错误:
没有3 - 显然有dflt ctor - 那是怎么回事?
没有2 - 为什么它是未知的大小?我已经指定int为一个类型,为什么它是未知的?
没有1 - 完全是2
感谢您的任何帮助。
感谢大家对我的帮助解决这个问题
在那里搜索“>>”。空白是你的朋友。 – Potatoswatter 2010-09-16 11:26:07
你真的想重新实现标准库的功能吗?特别是,型特质? – Potatoswatter 2010-09-16 11:26:55
@Patatoswatter;)只是想每天学习新的东西。 ;) – 2010-09-16 11:30:36