Thread: array of objects

  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,817
    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, 07: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, 11:26 AM
  4. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  5. Adding objects to an array
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 11-27-2001, 09:24 AM