If you want to do something like that, try to use setters and getters methods, e.g. :
class Player
{
private:
int m_X;
int m_Y;
public:
int getX() const;
int getY() const;
void setX(int x);
void setY(int y);
}
Getters methods should be like:
int Player::getX()
{
return m_X;
}
And setters like:
void Player::setX(int x)
{
m_X = x;
}
Then you can do something them in this way:
Player player;
player.setX(5);
player.setY(10);
int playerXcoord = player.getX();
...
You can also handle both coords in one method:
void Player::setCoords(int x, int y)
{
m_X = x;
m_Y = y;
}
The advantage of this approach is that all of your class components can't be accessed directly outside the class. It prevents from accidental modifications.