|
-
October 25th, 1999, 07:28 AM
#1
linked lists
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.
-
October 25th, 1999, 07:37 AM
#2
Re: linked lists
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|