Thread: STL Linked List of class within class

  1. #1
    Registered User NixPhoeni's Avatar
    Join Date
    Aug 2001
    Posts
    10

    Question STL Linked List of class within class

    I have a class Character in my program and I want to have three linked lists of Characters as members of that class.

    class Character
    {
    ...
    std::list <Character> one;
    std::list <Character> two;
    std::list <Character> three;
    };

    This will not work, however, because the Character class isn't complete (it goes into an STL file when debugging and gives me an error).
    I have tried a std::list of void * to try to push_back Characters later, but that doesn't work. I have also tried void *s to try to typecast them to std::list <Character> in the constructor, didn't work either. Anybody have any ideas on how I can do this? Thanx...

    -Joe

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    Try lists of Character pointers.
    zen

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    65
    Why do you use three Character lists in a Character Class? I don't think this is a wise approach.

  4. #4
    Registered User NixPhoeni's Avatar
    Join Date
    Aug 2001
    Posts
    10

    Talking Zen's suggestion works!

    Thank you zen! You are brilliant! It now compiles and works.
    As for ozgulker, I don't quite understand your question. I didn't explain what kind of program I am making. I know that using three lists of Characters inside the class is one of the best ways I could approach my situation.
    -Joe
    -------------------------------------------
    To understand a program you must become both the machine and the program.
    --Alan Perlis

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked list of a class object?....
    By chadsxe in forum C++ Programming
    Replies: 6
    Last Post: 12-08-2005, 03:15 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Linked List
    By silicon in forum C++ Programming
    Replies: 5
    Last Post: 07-21-2004, 07:47 PM
  4. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  5. How to use Linked List?
    By MKashlev in forum C++ Programming
    Replies: 4
    Last Post: 08-06-2002, 07:11 AM