nested-name-specifier

不问归期 提交于 2019-12-04 17:09:56

问题


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:

.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?


回答1:


The typename is not needed there, and is therefore not allowed.

MSVC do not parse templates properly until they are actually used, so some errors are not found until later.




回答2:


"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 .... In your case you don't have to use typename.




回答3:


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

See the gcc-4.5 output here. (it holds true for myownmap being class or function)



来源:https://stackoverflow.com/questions/6489351/nested-name-specifier

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!