Thread: multiple object instances at runtime

  1. #1

    multiple object instances at runtime

    im making a multiplayer game, and ive asked the user to input how many players to a numberOfPlayers variable

    i then want to create an instance of a player class for each player using a for loop..

    for(int p=1; p<=numberOfPlayers; p++)
    player ?????????;
    i want to make the player variables named player1, player2 etc..
    how can i do this?

    ps.. i can see im going to have to declare the player variables on the free store, but its just the naming of the variables im stuck with..

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Something like this maybe:
    playerClass *Players[MAXPLAYERS];
    for (int i = 0; i < NumOfPlayers; i++)
      Players[i] = new playerClass;
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Object Oriented and Multiple Files Basics?
    By markcls in forum C++ Programming
    Replies: 4
    Last Post: 03-25-2007, 12:21 PM
  2. Animating Multiple Object - [Open Gl]
    By Tonto in forum Game Programming
    Replies: 6
    Last Post: 09-29-2006, 06:31 PM
  3. Replies: 60
    Last Post: 12-20-2005, 11:36 PM
  4. A question about constructors...
    By Wolve in forum C++ Programming
    Replies: 9
    Last Post: 05-04-2005, 04:24 PM
  5. Exporting Object Hierarchies from a DLL
    By andy668 in forum C++ Programming
    Replies: 0
    Last Post: 10-20-2001, 01:26 PM