我在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