Thread: Map member of class produces error - why?

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    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".
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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をこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    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をこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.

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