container

This is a discussion on container within the C++ Programming forums, part of the General Programming Boards category; Hello, I have been developing in c++ for about 6 months. So, by no means am I an expert. I ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    2

    container

    Hello,
    I have been developing in c++ for about 6 months. So, by no means am I an expert. I have come across a problem where I need some sort of data structure to hold information in pairs - I think. I'm using Microsoft Visual C++. One of my problems is I have an object that is directly related to 1 other of the same object, but I would only like to show one object of the pair in a GUI. If that object is selected then somehow it triggers the object that is related to it and I remove both from my data strucuture.

    Lets say I have 10 distinct objects in my data structure.
    Then I would have 5 pairs or 5 objects that are related to another object in the data strucutre.
    They are related by date or price.

    Can anyone help me with a solution? I'm not sure if I'm making sense, lol.

    -Alex.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    STL has a "pair" that holds two items that belong together in some fashion.

    Not sure if that's much help or not.

    http://www.sgi.com/tech/stl/pair.html

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,755
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    2
    Yeah, I can see how that would work. Can I have a std::set<type pair> set1
    container?
    Thanks!
    -Alex.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,127
    If you are going to use a std::set<std::pair<T1, T2> >, a std::map<T1, T2> may be appropriate.
    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

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    If you have a key-value situation, where one type is always the type you use to uniquely identify a pair, then use a map. If a pair is uniquely identified by both types, then you can use a set<pair<T1, T2>, comparator> where comparator is a custom function or object for comparing pair<T1, T2> objects.

    So which you choose depends on how you would uniquely identify an object in your container.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting container
    By l2u in forum C++ Programming
    Replies: 6
    Last Post: 09-01-2007, 02:12 PM
  2. stl container to store more than 1 type
    By sujeet1 in forum C++ Programming
    Replies: 7
    Last Post: 05-09-2007, 05:10 AM
  3. inherited classes and stl container
    By rahulsk1947 in forum C++ Programming
    Replies: 9
    Last Post: 05-05-2007, 03:27 PM
  4. Replies: 1
    Last Post: 01-23-2006, 07:12 PM
  5. Linked List Queue Implementation help
    By Kenogu Labz in forum C++ Programming
    Replies: 8
    Last Post: 09-21-2005, 11:14 AM

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