about objects

This is a discussion on about objects within the C++ Programming forums, part of the General Programming Boards category; hi i have many object and i overloaded operator + in my class i want let user to choose objects. ...

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    17

    about objects

    hi
    i have many object and i overloaded operator + in my class
    i want let user to choose objects.
    so i get the name of subjects from user
    now how can run function +
    (for example user enter A and B how can i run (A+B )

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,717
    If you want to refer to the variables by name based on user input, perhaps you could use a std::map.
    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

  3. #3
    Registered User
    Join Date
    Dec 2008
    Posts
    17
    Quote Originally Posted by laserlight View Post
    If you want to refer to the variables by name based on user input, perhaps you could use a std::map.
    thank you but is there another way

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,717
    Quote Originally Posted by aminpost
    thank you but is there another way
    Maybe, but why do you reject the approach that I have suggested?
    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

  5. #5
    Registered User
    Join Date
    Dec 2008
    Posts
    17
    Quote Originally Posted by laserlight View Post
    Maybe, but why do you reject the approach that I have suggested?
    because i should work with array for example arrays that stores object name
    but i do not know how

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,717
    Quote Originally Posted by aminpost
    because i should work with array for example arrays that stores object name
    What made you come to the conclusion that you should use an array of objects that know their own name (or rather, are assigned names by which they can be referenced)? It is certainly possible, but you would need to keep the array in sorted order by "object name" in order to use binary search. A std::map or std::tr1::unordered_map is likely to be easier.
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Global objects and exceptions
    By drrngrvy in forum C++ Programming
    Replies: 1
    Last Post: 09-29-2006, 07:37 AM
  2. Replies: 60
    Last Post: 12-20-2005, 10:36 PM
  3. Question about cout an stack object?
    By joenching in forum C++ Programming
    Replies: 8
    Last Post: 05-08-2005, 10:10 PM
  4. chain of objects within pop framework help needed
    By Davey in forum C++ Programming
    Replies: 0
    Last Post: 04-15-2004, 10:01 AM
  5. array of objects?
    By *~*~*~* in forum C++ Programming
    Replies: 4
    Last Post: 05-31-2003, 05:57 PM

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