2010-05-01 7 views
0

이 질문에 간단한 수정이 필요하고 매우 작습니다.C++ 2d 배열 클래스 함수 호출 도움말

나는 대학에서 C++의 두 번째 학기를 마쳤으며 방금 OOP에 들어갔다. 이것은 내 첫 OOP 프로그램이며, 그것은 나에게 약간의 문제를 일으키고있다. 다음은 내가받는 오류입니다.

Member function must be called or its address taken in function displayGrid(int,Cell (*)[20]) 
Member function must be called or its address taken in function Turn(int,int,Cell (*)[20]) 
Member function must be called or its address taken in function Turn(int,int,Cell (*)[20]) 
Warning: Parameter 'grid' is never used in function displayGrid(int,Cell (*)[20]) 

다음은 모두 내 코드입니다. 나는 그것이 필요한 것보다 훨씬 더 많은 코드임을 알고있다. 더 어렵게 만들면 유감스럽게 생각한다. 내가 실수로 뭔가를 삭제할 수 있다고 걱정했습니다.

const int MAX=20; 

//Struct Cell holds player and their symbol. 
class Cell 
{ 
private: 
    int Player; 
    char Symbol; 

public: 
    Cell(void); 
    void setPlayer(int); 
    void setSymbol(char); 
    int getPlayer(void); 
    char getSymbol(void); 

}; 
Cell::Cell(void) 
{ 
    Symbol ='-'; 
} 

void Cell::setPlayer(int player_num) 
{ 
    Player = player_num; 
} 

void Cell::setSymbol(char rps) 
{ 
    Symbol = rps; 
} 

int Cell::getPlayer(void) 
{ 
    return Player; 
} 

char Cell::getSymbol(void) 
{ 
    return Symbol; 
} 

    void Turn(int, int, Cell[MAX][MAX]); 
    void displayGrid(int, Cell[MAX][MAX]); 

void main(void) 
{ 
int size; 

cout << "How big would you like the grid to be: "; 
cin >> size; 

    //Checks to see valid grid size 
while(size>MAX || size<3) 
{ 
    cout << "Grid size must between 20 and 3." << endl; 
    cout << "Please re-enter the grid size: "; 
    cin >> size; 
} 

int cnt=1; 
int full; 
Cell grid[MAX][MAX]; 

//I use full to detect when the game is over by squaring size. 
full = size*size; 
cout << "Starting a new game." << endl; 

//Exits loop when cnt reaches full. 
while(cnt<full+1) 
{ 
    displayGrid(size, grid); //calls function to display grid 

    if(cnt%2==0) //if cnt is even then it's 2nd players turn 
    cout << "Player 2's turn." << endl; 
    else 
    cout << "Player 1's turn" << endl; 

    Turn(size, cnt, grid); //calls Turn do each players turn 

    cnt++; 
} 

cout << endl; 

cout << "Board is full... Game Over" << endl; 
} 


void displayGrid(int size, Cell grid[MAX][MAX]) 
{ 
    cout << endl; 
    cout << " "; 

    for(int x=1; x<size+1; x++)  // prints first row 
    cout << setw(3) << x;  // of numbers. 

    cout << endl; 

    //Nested-For prints the grid. 
    for(int i=1; i<size+1; i++) 
    { 
    cout << setw(2) << i; 

    for(int c=1; c<size+1; c++) 
    { 
    cout << setw(3) << grid[i][c].getSymbol; 
    } 
    cout << endl; 
    } 

    cout << endl; 
    } 

void Turn(int size, int cnt, Cell grid[MAX][MAX]) 
    { 
    char temp; 
    char choice; 
    int row=0; 
    int column=0; 

    cout << "Enter the Row: "; 
    cin >> row; 

    cout << "Enter the Column: "; 
    cin >> column; 

    //puts what is in the current cell in "temp" 
    temp = grid[row][column].getSymbol; 

    //Checks to see if temp is occupied or not 
    while(temp!='-') 
    { 
    cout << "Cell space is Occupied..." << endl; 
    cout << "Enter the Row: "; 
    cin >> row; 

    cout << "Enter the Column: "; 
    cin >> column; 

      temp = grid[row][column].getSymbol; //exits loop when finally correct 
    } 

    if(cnt%2==0) //if cnt is even then its player 2's turn 
    { 
    cout << "Enter your Symbol R, P, or S (Capitals): "; 
    cin >> choice; 
    grid[row][column].setPlayer(1); 

    in >> choice; 
     } 

    //officially sets choice to grid cell 
     grid[row][column].setSymbol(choice); 
    } 

    else //if cnt is odd then its player 1's turn 
    { 
    cout << "Enter your Symbol r, p, or s (Lower-Case): "; 
    cin >> choice; 
    grid[row][column].setPlayer(2); 

    //checks for valid input by user1 
    while(choice!= 'r' && choice!='p' && choice!='s') 
    { 
    cout << "Invalid Symbol... Please Re-Enter: "; 
    cin >> choice; 
     } 

    //officially sets choice to grid cell. 
     grid[row][column].setSymbol(choice); 
    } 

    cout << endl; 
    } 

감사합니다.

+0

그것은 도움이 될 것입니다 –

답변

2

다음 줄 :

cout << setw(3) << grid[i][c].getSymbol; 

이 함수를 호출하지 않습니다. 대신 다음과 같이 작성하십시오.

cout << setw(3) << grid[i][c].getSymbol(); 

다른 오류 메시지와 마찬가지로 말하십시오.

오류 라인은 displayGridgrid 매개 변수를 사용하는 유일한 시간이기 때문에 경고가 생성됩니다.

cout << setw(3) << grid[i][c].getSymbol; 

은 다음과 같아야합니다 : 당신이 코드 수율하는 라인 오류를 지적하는 경우

cout << setw(3) << grid[i][c].getSymbol(); 
0

당신은 함수가 괄호 잊어 버렸습니다.
+0

와우 ... 고마워. 나는 지금 어리 석다. – user391686