c++ - g 编译器错误与 map<T, int>::iterator

标签 c++ g++

使用 Visual Studio 2012 时,以下代码编译无误(T 是模板参数):

pair<map<T, int>::iterator, bool> ret;

但是,当我使用 g++ 时,它会抛出错误消息

error: type/value mismatch at argument 1 in template parameter list for template<class _T1, class _T2> struct std::pair

出于某种原因,它无法识别 map<T, int>::iterator作为一种类型。我应该如何为 g++ 解决这个问题?

最佳答案

你需要告诉编译器合格的 id map<T, int>::iterator确实是一个类型(它可以是一个静态成员)

pair<typename map<T, int>::iterator, bool> ret;
     ^^^^^^^^

似乎 for once 一如既往 VS 的推导更好 比 g++ 错误。

关于c++ - g 编译器错误与 map<T, int>::iterator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16103201/

相关文章:

c++ - g++ makefile 错误 : *. o: 没有那个文件或目录

c++ - 为什么 g++ 链接器不警告这个不一致的函数声明?

c++ - OpenGL FBO - 白色像素显得透明

c++ - 从静态库中删除所有符号是否会阻止链接?

c++ - 无法访问模板基类中的变量

c++ - 为什么关于未初始化变量的 g++ 警告取决于变量的类型? (它警告一个 int 但不是一个 double)

php - 将此 C 函数翻译成 PHP

c++ - 无法设置用户可以输入的数字范围

c++ - 迭代多个序列。 C++11 中的容器

c++ - 声明如何与自身冲突?