我想在C++中声明一个使用模板的无序映射。但是,正如我期望的对象是原始数据类型之一,我不想为一个对象声明自定义类。使用模板的C++无序映射
我已经尝试使用:
template <class T> std::unordered_map<int, T> storedObj;
,但我不断收到错误:'storedObj' 没有在这个范围内声明
的代码片断低于
#include<iostream>
#include<unordered_map>
#include<deque>
std::deque<int> freeIds;
template <class T> std::unordered_map<int, T> storedObj;
unsigned static int objIdCount=0;
const unsigned long int MAXID = 1000000000;
你能告诉我有什么问题吗?谢谢。