Click to See Complete Forum and Search --> : linked lists


Hyena
October 25th, 1999, 07:28 AM
is it possible to make a linked list of objects? for example, if i made an object called card and defined it as follows-

class oneCard {
public:
char face[10];
char suit[10]
int value;
};

could i make a stack of oneCards? i already made a functioning linked list for integers, but im not sure how to do it for objects.

Tomaz Stih
October 25th, 1999, 07:37 AM
Of course it is possible. You declare class as
class oneCard {
public:
char face[10];
char suit[10]
int value;
oneCard *next; // points to next element in the list
};


and voila. You have a single linked list. In real world though you would not use linked lists but instead some component (stl or mfc container) to store your objects. For example:

class oneCard {
public:
char face[10];
char suit[10]
int value;
};
list<oneCard> cards; // declares an STL list of cards
CTypedPtrList<CPtrList, oneCard*> pointers_to_cards; // declare a MFC list of card pointers.



--- rating will attract gurus.