Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

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

like image 739
akashihi Avatar asked Jun 27 '11 06:06

akashihi


Video Answer


3 Answers

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.

like image 131
Bo Persson Avatar answered Oct 23 '22 19:10

Bo Persson


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

like image 36
Grigor Gevorgyan Avatar answered Oct 23 '22 18:10

Grigor Gevorgyan


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)

like image 6
iammilind Avatar answered Oct 23 '22 18:10

iammilind