Need advice about list of lists

This is a discussion on Need advice about list of lists within the C++ Programming forums, part of the General Programming Boards category; Hi guys, I have list of class contain list of another class. Code: MyMessages class { ID list <myPackets> Packets; ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    4

    Need advice about list of lists

    Hi guys,
    I have list of class contain list of another class.
    Code:
    MyMessages class
    {
       ID
       list <myPackets> Packets;
    }
    
    myPackets class
    {
       Seq
      Text
    }
    I need advice which one is the right way to set myMessages class??

    Code:
    void set_myMessages(const int &ID, list <myPackets> Packets)
    OR
    Code:
    void set_myMessages(const string &ID, string Seq, string Text)
    and also I need advice how to make a list of class.
    atm I use,

    Code:
    list <myPackets> listPackets;
    myPackets Packets;
    
    Packets.set(seq,text);
    listPackets.push_back(Packets);
    
    Packets.set(seq,text);
    listPackets.push_back(Packets);
    It does work but, I couldn't print the listPackets using iterator?
    so How do I print my list??? Also I need to sort list of my Packets, but
    my list of packet contain 2 element seq and text, so I couldn't use sort() funtion, so any Idea how I sorting the data??
    Thank You So Much

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,980
    Quote Originally Posted by handytxg
    I need advice which one is the right way to set myMessages class??
    You might want to elaborate on what your MyMessages class models, what is the class interface that you currently have in mind, and what this function in question is supposed to do.

    Quote Originally Posted by handytxg
    It does work but, I couldn't print the listPackets using iterator?
    Using an iterator is probably the right way to do traverse a std::list.

    Quote Originally Posted by handytxg
    Also I need to sort list of my Packets, but
    my list of packet contain 2 element seq and text, so I couldn't use sort() funtion, so any Idea how I sorting the data??
    If it makes sense in general, you could overload operator< for your myPackets class. If it does not make sense in general, then you could define a predicate function or function object that compares myPackets objects with a "less than" ordering, and then you can pass that function or function object to the std::list sort member function.
    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
    Apr 2009
    Posts
    4
    laserlight thank you for all the input,
    Finally I be able to make it works.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Recursion Revisited again, and again!
    By clegs in forum C++ Programming
    Replies: 93
    Last Post: 12-08-2007, 07:02 PM
  2. Merging two lists as one
    By Lone in forum C++ Programming
    Replies: 1
    Last Post: 03-17-2005, 02:59 PM
  3. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  4. 1st Class LIST ADT
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 11-09-2001, 06:29 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM

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