无法从受保护的值返回值

时间:2019-02-19 15:06:25

标签: c++ visual-c++

我试图用Visual C ++创建一个俄罗斯方块游戏作为宠物项目。我创建了一个类来保存每个部分,并在该类中具有受保护的变量。当我尝试创建能够更改和设置这些值的函数时,遇到了以下四个错误:

   expression must be a modifiable |value (on line 31)
   expression must be a modifiable |value (on line 32)
   explicit type is missing('int'assumed) [when i put in an int for that 
   function it expects an identifier] (on line 38)
   return value type does not match the function type (on line 40)

这是我的代码:

class Tetris
{
protected:
    int x[4];
    int y[4];
    int ID;
    int piece;
    int rotation;

public:
    Tetris(int &x, int &y, int ID, int piece, int rotation);

    int getX();
    void setX(int &x);

    int getY();
    void setY(int &y);

    int getID();
    void setID(int ID);

    int getPiece();
    void setPiece(int piece);

    int getRotation();
    void setRotation(int rotation);
};

Tetris::Tetris(int &x, int &y, int ID, int piece, int rotation)
{
    this->x = x;
    this->y = y;
    this->ID = ID;
    this->piece = piece;
    this->rotation = rotation;
}

Tetris::int getX()
{
    return x;
}

0 个答案:

没有答案