James Kanze
12/2/2008 1:27:00 PM
On Dec 2, 4:54 am, "jason.cipri...@gmail.com"
<jason.cipri...@gmail.com> wrote:
> On Dec 1, 6:54 pm, Christian Hackl <ha...@sbox.tugraz.at> wrote:
> > aTuL ha scritto:
> > > I want to create a map of key and another map object (it
> > > is another map of key value pairs). I have declared it as
> > > map<int, map<short, short>> mpObj; it gives me an error
> > > that, "error: ISO C++ forbids declaration of ?map? with no
> > > type". Does this mean I can not create a map of a map the
> > > object? Have I done something wrong? Any pointers to any
> > > tutorial?
> > On second thought, the >> is probably not the cause of this
> > particular error. Have you included <map> and is there a
> > using std::map somewhere?
> The error he got is reasonable:
It's hard to say what is reasonable when it comes to compiler
error messages these days:-).
> map<int, map<short, short>> mpObj;
> Could be parsed as:
> (map < int) , (map < short) , (short >> mpObj);
> And the error "declaration of map with no type" comes from the
> seemingly implicit declaration of "map" in "(map < int)".
Trying to indicate grouping with parentheses in this case
doesn't work. What the compiler sees (and is required to see,
according to the standard) is:
symbol map
punct '<', open template arg. list, if map is found at
global scope and is a template, otherwise less than
keyword int
punct ','
symbol map
punct '<' (as above)
short keyword
keyword short
punct ','
keyword short
punct '>>', which can only be shift right, regardless of
context
symbol myObj
punct ';'
Obviously, that token sequence can't be legal, regardless of
whether the compiler finds the symbol map or not. (If it
doesn't find map, there's no way < can have a keyword typename
as its right argument, and if it does, the opening of the
template arguments must be closed before the ';'.)
The next version of the standard will contain special wording or
grammar productions to the effect that you can close two
template argument lists at once (provided two are open) with a
>> token.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34