Thread: Getting classes to reference each other

  1. #16
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    I just edited my last post, a few seconds before you posted.

    There I gave a solution of how item could be made independent. I was just thinking, a more elegant way to deal with the items is to remove the global array of items and let both room and character have items.

    If a character wants to have an item in a room, then it could first ask the room which items it has available and then take some of the items. You add the items as a vector in your classes. When character calls the interface getItem of room, this vector should get smaller and the element should be added to the vector of character.

    This means that in character.h and room.h you have to include item.h, because character and room have items. Also in character.h you have to include room.h, since character will be using room.

  2. #17
    Registered User
    Join Date
    Jan 2003
    Posts
    42
    Hey, that's a good idea. I think I'll go about doing that. It's a lot more intuitive than the item controlling where it goes. After all, it's the character who gets/drops an item, so the item shouldn't even have to worry about that. Good call!

    -edit-
    Heh. Looks like I'll need to restructure my code a bit. Because my items are loaded after my rooms, I'll have to use a local array to store the items temporarily and put the in the room as needed. Smooth sailing, though!
    Last edited by Vorok; 01-05-2003 at 06:01 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. A general quaetion on portability
    By kris.c in forum C Programming
    Replies: 7
    Last Post: 07-20-2006, 03:48 AM
  4. problem with the library
    By kris.c in forum C Programming
    Replies: 21
    Last Post: 07-10-2006, 08:29 PM