I'm trying to fill the fields of an array contained in a structure that is contained in another structure.
Here are the structures definitions:
struct Team
{
std::string name;
int position;
int **matches;
};
struct Championship
{
Team *teams;
unsigned int size;
};
Then, I allocate the memory in a function.
Championship *createChampions(unsigned int n)
{
int i;
Championship *ptrcamp;
ptrcamp = new Championship;
ptrcamp -> size;
ptrcamp -> teams = new Team [n];
ptrcamp -> teams -> name;
ptrcamp -> teams -> position;
ptrcamp -> teams -> matches = new int *[2];
for (i = 0; i < 2; i++)
{
ptrcamp -> equipos -> partidos[i] = new int [n - 1];
}
return ptrcamp;
}`
The problems occurs when I try to save the values for each team in the "matrix" created dynamically.
void fillcamp(Championship ptrcamp, int n)
{
int i, j, k;
string s;
for (i = 0; i<n; i++)
{
cin >> ptrcamp.teams[i].name;
cin >> ptrcamp.teams[i].position;
cout << ptrcamp.teams[i].name;
cout << ptrcamp.teams[i].position;
for (j = 0; j < 2; j++) // With this I pretend to fill each column.
{
for (k = 0; k < n - 1; k++)// In this step I tried to fill the matrix
{
ptrcamp.teams[i].*(*(matches + k) + j) = -1;
}
}
}
}
So the Compiler says:
> Campeonato.cpp(52): error : identifier "matches" is undefined
1> ptrcamp.teams[i].*(*(matches + k) + j) = -1;
I tried everything, the fact is that using the traditional *var[n] notation its not permited. Instead, I can use *(var+n).
Thanks for the help guys.