VS2013编译含模板代码时的问题

sepcity sepcity 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我在VS2013编译模板的时候遇到了很奇怪的问题...
简化代码如下
#include <unordered_map>

template<typename Type, typename Key>
class KVM
{
public:
typedef std::unordered_map<Key, Type> ObjectMap;
typedef ObjectMap::iterator ObjectMapIter;
};

int main(int argc, char* argv[])
{
KVM<int, int> kvm;
return 0;
}
这个报编译错误
1>------ 已启动生成: 项目: TemplateTest, 配置: Debug Win32 ------
1> TemplateTest.cpp
1>e:\myproject\templatetest\templatetest\templatetest.cpp(8): warning C4346: “std::unordered_map<Key,Type,std::hash<Key>,std::equal_to<Key>,std::allocator<std::pair<const Key,Type>>>::iterator”: 依赖名称不是类型
1> 用“typename”为前缀来表示类型
1> e:\myproject\templatetest\templatetest\templatetest.cpp(9): 参见对正在编译的类 模板 实例化“KVM<Type,Key>”的引用
1>e:\myproject\templatetest\templatetest\templatetest.cpp(8): error C2146: 语法错误: 缺少“;”(在标识符“ObjectMapIter”的前面)
1>e:\myproject\templatetest\templatetest\templatetest.cpp(8): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========

哪位大神指导如何解决??
...全文
评论 4
收藏 已收藏
分享
返回顶部
sepcity
VC/MFC 16,551 成员 421,605 内容