将一个 class' 对象设置为另一个 class' 方法

set one class' object into another class' method

我必须根据这个 GT testCase 编写我的方法:

TEST(playerTest, setGameTest) {

    Player p;
    Game g;
    p.setGame(&g);
    EXPECT_EQ(&g, p.getGame());
}

现在 Player.h 有这些:

Game* game;

void setGame(Game* g);
Game getGame();

Player.cpp

void Player::setGame(Game* g) {
    this->game =  g;
}


int Player::getGame() {
    return this->game;
}

但由于指针类型不兼容,这些不适用于测试。如果我也能得到一些解释以及解决方案,我将不胜感激。

您的 setter 和 getter 没有正确的签名

void Player::setGame(Game* g)
{
    game = g;
}

Game* Player::getGame() const
{
    return game;
}