相关疑难解决方法(0)

键入一个模板类,而不指定模板参数

我正在尝试输入undedered_map或std :: map,这取决于是否有可用的TR1库.但我不想指定模板参数.从我到目前为止所读到的,在官方c ++ 0x标准可用之前,不能使用不带参数的typedef'ing模板.那么有谁知道这个优雅的解决方法?

#ifdef _TR1
#include <unordered_map> 
typedef std::tr1::unordered_map MyMap; //error C2976: too few template arguments
#else
#include <map> 
typedef std::map MyMap; //error C2976: too few template arguments
#endif
Run Code Online (Sandbox Code Playgroud)

c++ templates typedef tr1 c++11

26
推荐指数
1
解决办法
2万
查看次数

为模板化类创建类型别名

而不是使用

std::vector<Object> ObjectArray;
Run Code Online (Sandbox Code Playgroud)

我希望它是

MyArray<Object> ObjectArray;
Run Code Online (Sandbox Code Playgroud)

保留所有std :: vector方法.(比如push_back(),reserve(),...等)

但是,使用

typedef std::vector MyArray;
Run Code Online (Sandbox Code Playgroud)

不行.我应该使用模板吗?怎么样?

c++

9
推荐指数
3
解决办法
3251
查看次数

typedef std容器?

我想做

typedef deque type; //error, use of class template requires template argument list
type<int> container_;
Run Code Online (Sandbox Code Playgroud)

但是这个错误阻止了我.我该怎么做呢?

c++ templates typedef

3
推荐指数
2
解决办法
1921
查看次数

标签 统计

c++ ×3

templates ×2

typedef ×2

c++11 ×1

tr1 ×1