0

I have to write my method according to this GT testCase:

TEST(playerTest, setGameTest) {

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

Now Player.h has these:

Game* game;

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

Player.cpp

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


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

but these don't work with the test due to incompatible pointer types. I would appreciate if I could also get some explanation along with the solution.

1 Answers1

0

Your setter and getter do not have the right signatures

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

Game* Player::getGame() const
{
    return game;
}
Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
  • The getter doesn't work. Even if change the definition ```Game getGame();```to ```Game* getGame();``` –  Apr 02 '20 at 12:06
  • Note that I added `const` to the end of the method. https://stackoverflow.com/questions/751681/meaning-of-const-last-in-a-function-declaration-of-a-class/751694 So the new signature is `Game* getGame() const;` – Cory Kramer Apr 02 '20 at 12:13