I am getting an error ‘return type does not match function type’ when I am trying to return a pointer to a player in my function. The error from the compiler is:
‘&’ : illegal operation on bound member function expression
CPlayer* CLevel::getPlayer()
{
return &player;
}
In the header file, this is defined as:
private:
CPlayer player(Point p, CGame* game);
public:
CPlayer* getPlayer();
Any ideas as to why I am getting this error and how I can remove it?
EDIT:
Level constructor:
CLevel::CLevel()
{
Point p;
this->game=game;
p.x=0;
p.y=0;
player(Point p, CGame* game) {};
memset(tiles, GROUND, sizeof(TileType)*GRID_HEIGHT*GRID_WIDTH);
}
Player.cpp constructor:
CPlayer::CPlayer(Point pos, CGame* game)
{
this->game=game;
Point p;
p.x=0;
p.y=0;
setPosition(p);
}
Because in your code,
playeris the name of a private function:This is a function that takes a
Point, aCGame*, and returns aCPlayer.To declare a
CPlayerdata member you needwhich you can then initialize in the constructor, for example:
and:
Or, in C++11, you can do it like this: