我正在尝试从 Udacity 学习 C++。我需要澄清一下我的理解是否正确。所以代码如下。
井字游戏:
class Board
{//the class tracks the game and the winner
char positionsSelected[16];
char winner;
public:
//Constructor
Board();
int setPosition(int gridNumber, char user);
char* getPositions(void);
};
char* getPositions(void)
{//return all the positions on the board
return positionsSelected;
}
Run Code Online (Sandbox Code Playgroud)
如果你看一下,成员函数char* getPositions(void)是在类内部声明的。
我知道假设可能真的很糟糕,但这就是我的思考过程和问题
由于您基本上是在阅读一系列字符,这就是为什么它必须是char*.
为什么必须的参数getPositions(void)?这可以与空括号 () 相同吗?
如果函数原型是char* getPositions(),是否意味着它返回了指针?我可以假设返回值char*getPosition(void)指向char array(positionsSelected).
如果我的假设是错误的 3. 我可以放这样的东西吗
char* getPositions(void){
char* pointers;
pointers = positionSelected;
return pointers;
}
Run Code Online (Sandbox Code Playgroud)
任何建议或解释将不胜感激。