[Langage] Passer par reference un tableau de int
Bonjour a tous,
J'aimerais passer par reference un tableau de int pour pouvoir en modifier le contenu et conserver cette modification.
Or j'ai des erreurs de compilation de type "overloaded member function...." avec ceci :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
void resolution::aff()
{
int tab_solution[_NB_CASES] = SOLUTION;
resolution().settab_solution(tab_solution); //demande de modification ici
for (int i=0 ; i<_NB_CASES ; i++ )
{
if (!(i%_LARGEUR))
cout << endl;
cout << resolution().gettab_solution(i) << endl;
}
}
int resolution::gettab_solution(int i)
{
return this->_tab_solution[i];
}
void resolution::settab_solution(int (&tab)[_NB_CASES])
{
for (int i = 0; i < _NB_CASES; i++)
this->_tab_solution[i] = tab[i]; //modif ici
} |
ou alors lorsque je l'affiche avec ce code : j'ai de la merdouille... (normal car je ne passe pas la reference du tableau)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
void resolution::aff()
{
int tab_solution[_NB_CASES] = SOLUTION;
resolution().settab_solution(tab_solution); //demande de modification ici
for (int i=0 ; i<_NB_CASES ; i++ )
{
if (!(i%_LARGEUR))
cout << endl;
cout << resolution().gettab_solution(i) << endl;
}
}
int resolution::gettab_solution(int i)
{
return this->_tab_solution[i];
}
void resolution::settab_solution(int *tab)
{
for (int i = 0; i < _NB_CASES; i++)
this->_tab_solution[i] = tab[i]; //copie ici
} |
Je suis un peu perdu, je pense que c'est possible mais j'ai essayer pas mal de trucs trouves sur google, mais toujours des erreurs de compilation :(
Merci d'avance