c++ - 嵌套名称说明符

标签 c++ templates generic-programming

我有这样的代码:

namespace mymap {
    template <class Key,template <typename T > class Allocator> myownmap {
        typedef pair<const unsigned int, Key> typename _myPair;
        typedef multimap<unsigned int, Key,less<Key> ,Allocator<_myPair> > typename _entriesType;
    }
}

它在 MSVC 下编译成功(并且可以工作),但 gcc 提示语法无效:

.hpp:20: error: expected nested-name-specifier before ‘_myPair’
.hpp:20: error: two or more data types in declaration of ‘_myPair’

我做错了什么?

最佳答案

那里不需要typename,因此是不允许的。

MSVC 直到实际使用模板才正确解析模板,所以有些错误要到以后才发现。

关于c++ - 嵌套名称说明符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6489351/

相关文章:

c++ - 关于shared_ptr、scoped_ptr和shared_array的一些问题

c++ - Visual C++ 异或加密错误

templates - 如何使用 Emacs+AUCTeX 创建(自动插入)LaTeX 模板?

c++ - 使用强类型枚举的模板参数推导

java - 传递参数的通用方法 - java.lang.ClassCastException : com. google.gson.internal.LinkedTreeMap

c++ - 切片 DLL 句柄类

c++ - 具有默认参数作为模板类型的函数

c++ - 具有代理迭代器/引用和自动的容器

C++ 模板类 : template paramaters given at runtime, 如何避免重复的大型开关案例?

c++ - Unity 的 HLSL/Cg 预处理器工作方式不对?