Map member of class produces error - why?

This is a discussion on Map member of class produces error - why? within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by Programmer_P And yet it would not let me use the insert() function to insert things into the ...

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,725
    Quote Originally Posted by Programmer_P
    And yet it would not let me use the insert() function to insert things into the map, when it was just an instance and not a typedef. It was only when I changed it to use the '[]' and '=' operators, like in your example, that it compiled. Why is that?
    Show the code in which you tried to "use the insert() function to insert things into the map, when it was just an instance and not a typedef".
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by Elysia View Post
    The constructor of the map is invoked before the constructor body of your class.
    The map is ready to use since it's an object inside your class (not a pointer nor a reference).
    Ok, then I have no idea why I'm now getting another error with a different member map, one that is a copy of the original map and is assigned with the '=' operator of the map class inside a member function.
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

  3. #18
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    Show your code, please.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by laserlight View Post
    Show the code in which you tried to "use the inshttp://cboard.cprogramming.com/newreply.php?do=newreply&p=954825ert() function to insert things into the map, when it was just an instance and not a typedef".
    EDIT: Delete reply...

    My code has compiled.
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

  5. #20
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by Elysia View Post
    Show your code, please.
    No need. It was a noobie mistake. I accidentally forgot to prefix the member function definition that assigns one map to another map to make a copy of the map, then returns the copy, with the class name followed by the "::" operator, which is why it was saying the map copy name didn't exist in the scope.

    All good now.
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

  6. #21
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    aMap[currentNum - 1] = aStringVector.at(currentNum - 1);
    Map::Insert is a far better choice even though it is syntactically more complex.

  7. #22
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    Depends on what you need. If you are just going to insert without regard as to whether it's there or not, then the index operator might do the job.
    Any other reason it shouldn't be preferred?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  3. Replies: 6
    Last Post: 04-27-2006, 10:55 AM
  4. Is it possible to have callback function as a class member?
    By Aidman in forum Windows Programming
    Replies: 11
    Last Post: 08-01-2003, 11:45 AM
  5. SystemTray class
    By jair in forum C++ Programming
    Replies: 2
    Last Post: 07-28-2003, 06:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21