CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: linked lists

  1. #1
    Join Date
    May 1999
    Location
    wallingford, pennsylvania
    Posts
    70

    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.


  2. #2
    Join Date
    May 1999
    Location
    Slovenia (currently: Germany)
    Posts
    249

    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
  •  





Click Here to Expand Forum to Full Width

Featured