小编Sam*_*hoo的帖子

关于字符的C++初学者问题

我只是在试图制作一个简单的井字游戏时,正在搞乱一些C++,而我遇到了一些问题.这是我的代码:

#include <iostream>
using namespace std;

class Square {
public:
    char getState() const;
    void setState(char);
    Square();
    ~Square();
private:
    char * pState;
};

class Board {
public:
    Board();
    ~Board();
    void printBoard() const;
    Square getSquare(short x, short y) const;
private:
    Square board[3][3];
};

int main() {
    Board board;
    board.getSquare(1,2).setState('1');
    board.printBoard();
    return 0;
}

Square::Square() {
    pState = new char;
    *pState = ' ';
}
Square::~Square() {
    delete pState;
}
char Square::getState() const {
    return *pState;
}
void Square::setState(char set) {
    *pState = …
Run Code Online (Sandbox Code Playgroud)

c++

2
推荐指数
1
解决办法
255
查看次数

标签 统计

c++ ×1