嵌套名称说明符
nested-name-specifier
我有一个类似于的代码
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在实际使用模板之前不会正确解析模板,因此直到稍后才会发现一些错误。
"预期嵌套名称说明符"意味着在typename
关键字之后,您应该使用模板参数的某些嵌套名称,例如typedef typename Key::iterator ...
。在您的情况下,您不必使用typename
。
typedef pair<const unsigned int, Key> /*typename*/ _myPair;
^^^^^^^^^^^^ not needed
请参阅此处的gcc-4.5输出。(适用于myownmap
为class
或函数)
相关文章:
- 在 CRTP 中使用嵌套名称说明符
- C++预期的嵌套名称说明符
- 缩短成员函数作用域说明符(嵌套类)(C++)
- C++:在嵌套名称说明符中命名的不完整类型
- 使用另一个模板类的嵌套名称说明符专用化模板类
- 在嵌套名称说明符中使用枚举(编译器警告)
- 详细说明的类型说明符中的类型相关嵌套名称说明符
- 编译器错误,应为嵌套的名称说明符
- 嵌套名称说明符中使用的类型不完整
- 错误:不完整的类型..在嵌套名称说明符中使用
- 类型名称关键字和嵌套名称说明符
- 编译器错误:typedef 之前的预期嵌套名称说明符
- 错误:'xxx'之前应嵌套名称说明符
- 正在解析循环依赖的嵌套类型说明符
- 嵌套名称说明符中第一个命名空间名称的名称查找
- 前向声明问题:嵌套名称说明符中使用的类型不完整'enums::Category'
- 嵌套名称说明符中使用的不完整类型,为什么?
- 预期的嵌套名称说明符- gcc
- 嵌套名称说明符中的不完整类型
- 使用子类作为基类的模板参数和嵌套名称说明符