2015-12-10 61 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()))