map of objects

Discussion in 'C++' started by DerekBaker, Apr 19, 2008.

  1. DerekBaker

    DerekBaker Guest

    Why given this:

    C c(5, 6, 7); // C has two ctors: one takes 3 ints, one a single int.
    map<int, C> TestMap;

    is this ok?

    TestMap.insert(make_pair(1, c));

    but not this?

    TestMap[1] = c;

    Thanks
    --
    Derek
    DerekBaker, Apr 19, 2008
    #1
    1. Advertising

  2. DerekBaker

    DerekBaker Guest

    * DerekBaker:
    > Why given this:
    >
    > C c(5, 6, 7); // C has two ctors: one takes 3 ints, one a single int.
    > map<int, C> TestMap;
    >
    > is this ok?
    >
    > TestMap.insert(make_pair(1, c));
    >
    > but not this?
    >
    > TestMap[1] = c;
    >
    > Thanks


    Never mind, should have read my Josuttis first. Adding a default constructor works fine.

    --
    Derek
    DerekBaker, Apr 19, 2008
    #2
    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:
    618
    Lau Lei Cheong
    Feb 4, 2005
  2. Matthias Hildebrand
    Replies:
    5
    Views:
    7,926
    krogers
    Mar 20, 2012
  3. Vlad
    Replies:
    0
    Views:
    347
  4. Patrick Guio
    Replies:
    6
    Views:
    3,174
    chris
    Oct 20, 2004
  5. 7stud
    Replies:
    11
    Views:
    668
    Dennis Lee Bieber
    Mar 20, 2007
Loading...

Share This Page