-1

I am making a game of cards. At the begining I am asking for the number of players. Player is a class.

I was wondering how do I make an array of players.

Right now I have:

Player *listofplayers = new Player[size];

I get an error saying unknown array size declared.

On the other hand the below is perfectly fine.

int *i = new int[size];

Can you please explain the difference between the two?? And what the correct declaration is?

Thanks in advance.

4

1 回答 1

1

您需要删除括号:

Player *listofplayers = new Player[size];

就像克里斯说的那样,既然你使用的是 C++,你应该使用 astd::vector代替:

#include <vector>

std::vector<Player> listofplayer(size);
// or:
// std::vector<Player> listofplayer;
// listofplayer.resize(size);
于 2013-07-09T02:49:25.477 回答