array of objects

This is a discussion on array of objects within the C++ Programming forums, part of the General Programming Boards category; im in a perdicament, i need to declare the monsters in my game. but im not exactly sure of how ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    196

    array of objects

    im in a perdicament, i need to declare the monsters in my game. but im not exactly sure of how to do that. so im turning to arrays, my original plan was just to do this

    Code:
    Character[2] = {Character badguy1,Character badguy2,Character badguy3};
    but that doesnt seem to work. does anyone know of a better way to declare my enemies or perhaps code that would essentially do the same as the code aboce.

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,806
    Code:
    Character badguy[3];
    
    ...
    
    badguy[0].some_method();
    
    cout << "The monster has " << badguy[2].GetHealth() << " health points." << endl;
    
    ...
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 08:39 AM
  2. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 09:51 AM
  3. Replies: 4
    Last Post: 10-16-2003, 12:26 PM
  4. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 01:04 PM
  5. Adding objects to an array
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 11-27-2001, 09:24 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21