我正在用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
错误具体如下: Cat :: getY&#39 ;:非标准语法;使用&#39;&amp;&#39;创建指向成员的指针
答案 0 :(得分:1)
看起来你不想要指向成员的指针。你刚忘记了函数调用中的括号。
if ((row == cat_.getY()) && (col == cat_.getX()))
答案 1 :(得分:0)
假设getY / getX是cat_的方法,而不是命名不好的公共变量, 此
if ((row == cat_.getY) && (col == cat_.getX))
应该是
if ((row == cat_.getY()) && (col == cat_.getX()))