简体   繁体   English

嵌套名称说明符

[英]nested-name-specifier

I have a code like: 我有一个代码:

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;
    }
}

It compiles successfully (and works) under MSVC, but gcc is complaining about invalid syntax: 它在MSVC下成功编译(和工作),但是gcc抱怨语法无效:

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

what i'm doing wrong? 我做错了什么?

The typename is not needed there, and is therefore not allowed. 那里不需要typename ,因此不允许使用。

MSVC do not parse templates properly until they are actually used, so some errors are not found until later. MSVC在实际使用之前不会正确解析模板,因此直到稍后才会发现某些错误。

"expected nested-name-specifier" means that after typename keyword you are expected to use some nested name of a template parameter, for example typedef typename Key::iterator ... . “expected nested-name-specifier”意味着在typename关键字之后,您应该使用模板参数的一些嵌套名称,例如typedef typename Key::iterator ... In your case you don't have to use typename . 在您的情况下,您不必使用typename

typedef pair<const unsigned int, Key> /*typename*/ _myPair;
                                      ^^^^^^^^^^^^ not needed

See the gcc-4.5 output here . 请在此处查看gcc-4.5输出 (it holds true for myownmap being class or function) (它适用于myownmapclass或函数)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM