Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > map of map.

Reply
Thread Tools

map of map.

 
 
aTuL
Guest
Posts: n/a
 
      12-01-2008
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.
 
Reply With Quote
 
 
 
 
Senthil
Guest
Posts: n/a
 
      12-01-2008
<snip>
>
> map<int, map<short, short> > mpObj;
>


Hard to note if you are new, you need the the space between the two
'>'.

<snip>

 
Reply With Quote
 
 
 
 
jason.cipriani@gmail.com
Guest
Posts: n/a
 
      12-02-2008
On Dec 1, 6:54*pm, Christian Hackl <(E-Mail Removed)> 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:

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
 
Reply With Quote
 
Bill Davy
Guest
Posts: n/a
 
      12-02-2008
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

"aTuL" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
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.


 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      12-02-2008
On Dec 2, 4:54 am, "(E-Mail Removed)"
<(E-Mail Removed)> wrote:
> On Dec 1, 6:54 pm, Christian Hackl <(E-Mail Removed)> 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:(E-Mail Removed)
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
std::map::find() throws exception when map is empty? Matthias Hildebrand C++ 5 03-20-2012 06:09 AM
I can map all files (.*) to asp.net worker.How do I map NO FILE to asp.net worker? alex ASP .Net 1 02-04-2005 03:18 AM
searching keys in std::map using map::upper_bound Erik Arner C++ 0 11-02-2004 11:14 PM
map.insert(key,val) vs. map[key]=val ? Patrick Guio C++ 6 10-20-2004 01:54 PM
map that maps to iterators in the same map ? Vlad C++ 0 12-15-2003 08:29 PM



Advertisments