map of map.

A

aTuL

Hi All,

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?

Atul.
 
J

jason.cipriani

aTuL ha scritto:


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:

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

Jason
 
B

Bill Davy

If it's hard to write it will be hard to read (especially in a year's time).

So why not divide and conquer?

typedef map<short,short> MapPhoneToMobileT;
typedef map<int, MapPhoneToMobileT> MapCustomerIdToMobileT;

Bill

Hi All,

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?

Atul.
 
J

James Kanze

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top