class game
{
struct player;
{
int position[20][20];
.....
...
}
}
I want to declare the objects of struct player such that the value of position for all of them should be diffrent. it will be not change throughout the program...how can i do it.You can use some public function of other tricks to do it,but please help....
class game
{
private:
struct _player // defines a datatype
{
int position[20][20];
} player[20]; // defines 20 players
public:
game() // default constructor
{
// A vector of 1000 numbers in order
std::vector<int> RandomVector;
for (int i = 0; i < 1000; ++i) RandomVector.push_back(i);
// A vector of 1000 number in random order
std::random_shuffle( RandomVector.begin(), RandomVector.end() );
// stick the first few random numbers into position[][] as they are all unique.
for (int i = 0; i < 20; ++i)
for (int j = 0; j < 20; ++j)
for (int k = 0; k < 20; ++k)
player[i].position[j][k]= RandomVector[k + 20*j];
}
};
Your struct player wasn't defined quite right, I'm trying to figure out exactley what you want. First you have to declare what the struct will hold, then you need to declare members of it. I'm guessing you want X,Y values of position and you want an array of players or something.