I have a series of variables including a struct that is declared in another file (Vek.h). In this file, I also declare a function called correct
:
class Vek: public Player{
protected :
int counter = 0;
struct next {int nexti=0; int nextj=0;};
next newNext = {0,0};
int jTemp;
int iTemp = 0;
int jPast;
int iPast;
int hits;
int pastHits = 0;
int count = 0;
void putShip(Cell[OCEAN_SIZE][OCEAN_SIZE]);
int correct(int, int, int, int, int, int, struct);
// int fire(vector<int>submit);
Coords shot;
In the second file (Vek.cpp) I try to call this function and pass the struct next
as a parameter:
int Vek :: correct(int iTemp, int jTemp, int iPast, int jPast, int hits, int count, struct newNext){
int attemptsi[2]{iTemp+1,iTemp-1};
int attemptsj[2]{jTemp+1,jTemp-1};
int i;
int j;
if(count == 0){
i = attemptsi[0];
j = jTemp;
// Coordinates.j = 5;
}else if(count == 1){
i = attemptsi[1];
j = jTemp;
// Coordinates.j = 5;
}else if(count == 2){
i = iTemp;
j = attemptsj[0];
// Coordinates.j = 5;
}else if(count == 3){
i = iTemp;
j = attemptsj[1];
// Coordinates.j = 5;
}
next.nexti = i;
next.nextj = j;
count++;
return next;
}
I'm getting an error calling correct
due to the struct. Among others I get the error:
out-of-line definition of 'correct' does not match any declaration in 'Vek'
What is going on here? How can I pass the struct next
to the correct
function?
Without spaces around correct
I get the error:
declaration of anonymous struct must be a definition