map of map.

Discussion in 'C++' started by aTuL, Dec 1, 2008.

  1. aTuL

    aTuL Guest

    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.
     
    aTuL, Dec 1, 2008
    #1
    1. Advertising

  2. aTuL

    Senthil Guest

    <snip>
    >
    > map<int, map<short, short> > mpObj;
    >


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

    <snip>
     
    Senthil, Dec 1, 2008
    #2
    1. Advertising

  3. aTuL

    Guest

    On Dec 1, 6:54 pm, Christian Hackl <> 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
     
    , Dec 2, 2008
    #3
  4. aTuL

    Bill Davy Guest

    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" <> wrote in message
    news:...
    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.
     
    Bill Davy, Dec 2, 2008
    #4
  5. aTuL

    James Kanze Guest

    On Dec 2, 4:54 am, ""
    <> wrote:
    > On Dec 1, 6:54 pm, Christian Hackl <> 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:
    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
     
    James Kanze, Dec 2, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. alex
    Replies:
    1
    Views:
    692
    Lau Lei Cheong
    Feb 4, 2005
  2. Matthias Hildebrand
    Replies:
    5
    Views:
    8,195
    krogers
    Mar 20, 2012
  3. Vlad
    Replies:
    0
    Views:
    389
  4. Patrick Guio
    Replies:
    6
    Views:
    3,266
    chris
    Oct 20, 2004
  5. Erik Arner
    Replies:
    0
    Views:
    1,338
    Erik Arner
    Nov 2, 2004
Loading...

Share This Page