无法解析将二维数组传递到函数中的外部因素

时间:2015-05-03 19:35:25

标签: c++ arrays

根据这个帖子passing a 2D array to a function中的ouha,这似乎格式正确,但我一直收到一个错误,指出我有未解析的外部但不是它们所在的行。 以下是让我头痛的代码

#include <iostream>
#include <fstream>

using namespace std;
const int MAZE_ROW= 10;
const int MAZE_COLUMN= 20;

//checking if the move is valid
//bool  moveCheck ( int move, int posi, int posj);
//gets the position where the player is at
void returnPosition (int &posi, int &posj, char maze[][MAZE_COLUMN]);
//prints the maze ... duh
//void printMaze (char maze[10][20]);



int main () {
//the row and column that the character is on. 
int posi, posj;
posi = 2;
posj=1;

//bool win, good, quit;
   //win = 0;
//quit = 0;

//maze array
char maze[MAZE_ROW][MAZE_COLUMN];
///DMT*/cout << "BOOTY";
///DMT*/cin >>maze[1][1];
///DMT*/cout << maze[1][1];

//getting the maze from a fille named maze.txt
ifstream inData;
ofstream outData;
inData.open ("maze.txt");
 for (int i=0;i<10; i++){
    for (int j=0; j<20; j++){
        inData >> maze [i][j] ;
    }
 }

cout << maze [1][1] <<endl;
inData.close();
//DMTtest good to here

 //basically printmaze()
  //this keeps getting corrupted
 //Run-Time Check Failure #2 - Stack around the variable 'maze' was     corrupted.
//fixed, test succesful through this loop
    for (int i=0;i<10; i++){
        for (int j=0; j<20; j++){
        cout << maze [i][j] ;
    }
    cout << endl;
}

    //more  testing
   //SPOT WHERE I TRY TO CALL FUNCTION
    returnPosition (posi, posj, maze);
    cout << " [" <<posi << "][" << posj << "]" << endl;
//printMaze(maze);
/*do {
    //putting everything together

    printMaze (maze);




}while (win ==0 && quit ==0);

if (win == 1){
    cout << "Congratulations!  You won!";
}
if (quit ==1){
    cout << "Sorry, you lost";
}*/


    system ("PAUSE");
    return 0;
}


/***** a function to print the maze for the user to see ***********
void printMaze (char maze[20][10]){

for (int i=0;i<10; i++){
        for (int j=0; j<20; j++){
        cout << maze [i][j] ;
    }
    cout << endl;
}
cout << "Next move (u=Up, d=Down, r=Right, l=Left, q=Quit)? ";

}*/


/*********** will return the position of the user *************/
/**/void returnPosition (int &posi, int &posj,int maze[][MAZE_COLUMN]){

char foo;
int i, j;
for (i=0;foo!='*'; i++){
    for (j=0; j<MAZE_ROW; j++){
        foo= maze[i][j];
    }
}
posi=i;
posj=j;
}/**/

1 个答案:

答案 0 :(得分:0)

// declaration
void returnPosition (int &posi, int &posj, char maze[][MAZE_COLUMN]);

// definition
void returnPosition (int &posi, int &posj, int maze[][MAZE_COLUMN]) {...}

这两个不匹配 - 因此声明的函数没有正文(定义)。选一个,我想你想要第一个。