2015-12-10 59 views
0

我在C++中創建了一個遊戲,並且我調用了一個函數,但是我收到一個錯誤,說我需要插入&符號來創建一個指向成員的指針。不過,我不確定這哪裏需要去...使用'&'來創建指向成員錯誤的指針

string MouseAndCatGame::prepareGrid(){ 
    //prepare a string that holds the grid information 
    ostringstream os; 
    for (int row(1); row <= SIZE; ++row) //for each row (vertically) 
    { 
     for (int col(1); col <= SIZE; ++col) //for each column (horizontally) 
     { 
      if ((row == cat_.getY) && (col == cat_.getX)) 
      { 
       os << cat_.getSymbol(); //show cat 
      } 
      else 
       if ((row == mouse_.getY()) && (col == mouse_.getX())) 
        os << mouse_.getSymbol(); //show mouse 
       else 
       { 
        bool holePresent(underground_.findHole(col, row)); 
        if (holePresent == true) // If there is a hole at that location 
        { 
         os << HOLE; // Show hole symbol 
        } 
        else 
        { 
         if ((row == nut_.getY()) && (col == nut_.getX())) 
         { 
          os << nut_.getSymbol(); //show mouse 
         } 
         else 
         { 
          os << FREECELL;//show free grid cell 
         } 
        } 
       } 
     } //end of col-loop 
     os << endl; 
    } //end of row-loop 
    return os.str(); 
} //end prepareGrid 

錯誤具體如下: 貓::的getY':非標準語法;使用'&'創建指向成員的指針

+1

你忘了括號。 if((row == cat_.getY())&&(col == cat_.getX()))'if((row == cat_.getY)&&(col == cat_.getX))'=>投票結束爲錯字。 – NathanOliver

回答

1

看起來您不想指向成員的指針。你只是在函數調用中忘記了括號。

  if ((row == cat_.getY()) && (col == cat_.getX())) 
+0

我不相信我沒有看到,謝謝哈哈。 – Cube3

0

假設的getY /信息getX是 cat_的方法,而不是命名不佳公共變量,這個

if ((row == cat_.getY) && (col == cat_.getX)) 

應該

if ((row == cat_.getY()) && (col == cat_.getX()))