954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Need advice about list of class of classes.

Hi guys,
I have list of class contain list of another class.

MyMessages class
{
ID
list <myPackets> Packets;
}

myPackets class
{
Seq
Text
}


I need advice which one is the right way to set myMessages class??

void set_myMessages(const int &ID, list <myPackets> Packets)

OR

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,

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

handytxg
Newbie Poster
7 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

You can look all that info up in a STL List reference, as the one found here:

http://www.cplusplus.com/reference/stl/list/

See the "STL Algorithms" for sorting data inside STL containers.

Clockowl
Posting Whiz
376 posts since May 2008
Reputation Points: 69
Solved Threads: 28
 
void set_myMessages(const int &ID, list Packets)

Hmm , good question , I have the past experience with dealing these
type of question. where you have to consider is list will
have a default constructor and a copy constructor and a assignment operator. Then this will work.

But if you using a big datastructures like this tell the linker to generate a big stack.Otherwise stackoverflows will be there.

NicAx64
Posting Pro
536 posts since Mar 2009
Reputation Points: 86
Solved Threads: 44
 

guys thank you for all the input,
Finally I be able to make it works.

handytxg
Newbie Poster
7 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You