我在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':非標準語法;使用'&'創建指向成員的指針
你忘了括號。 if((row == cat_.getY())&&(col == cat_.getX()))'if((row == cat_.getY)&&(col == cat_.getX))'=>投票結束爲錯字。 – NathanOliver