The language is C++.
I Googled tons of different results and looked at them, but I can't seem to find a specific answer to what I'm looking for.
I have a Player class, and I want to set his "state", but I want to do it from its public member function, because the state is an enumeration in his private section. I've tried various different ways, but the compiler keeps giving me errors. I know how to do it with other values, but when it comes to enumerations, I can't get it to work. I even tried references, and still no luck.
Here is sample code. Do you know what I'd have to change to get it work? Thanks.
#include <iostream>
using namespace std;
class Player
{
private:
enum State {IDLE, MOVING};
State playerState;
public:
Player();
~Player();
enum setPlayerState(enum &playerState ps);
enum getPlayerState();
};
Player::Player()
{
}
Player::~Player()
{
}
enum Player::setPlayerState(enum &playerState ps)
{
playerState = ps;
}
enum Player::getPlayerState()
{
return playerState;
}
int main()
{
Player player;
player.setPlayerState(MOVING);
cout << "The player's state is" player.getPlayerState() << "." << endl;
return 0;
}
I know how to set and get private integer values, but enumerations, I'm having no luck. I want to be able to type in the parameters player.setPlayerState(IDLE) OR player.setPlayerState(MOVING), but I don't know how to do it from the public member function.
If you know the answer, I just want to say Thank You, and I appreciate your time.