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

sepcity 2015-03-24 06:05:20
我在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 个 ==========

哪位大神指导如何解决??
...全文
123 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
oyljerry 2015-03-26
  • 打赏
  • 举报
回复
恭喜。
信阳毛尖 2015-03-24
  • 打赏
  • 举报
回复
sepcity 2015-03-24
  • 打赏
  • 举报
回复
这个问题已经解决 将 typedef ObjectMap::iterator ObjectMapIter; 改为 typedef typenameObjectMap::iterator ObjectMapIter; 即可

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧