Tuesday, February 26, 2019

c++ - Return the enumeration instead of the index

I have a simple class that uses an enum for "status". When I use the getStatus member function, it does indeed return "Busy" but when I print the value, it shows a "1". How can I print "Busy" instead of 1?


http://codepad.org/9NDlxxyU demonstration


#include 
using namespace std;
enum Status{Idle, Busy};
class text
{
public:
void SetStatus(Status s);
Status getStatus();
private:
Status s;
};
void text::SetStatus(Status s)
{
this->s = s;
}
Status text::getStatus()
{
return this->s;
}
int main()
{
text myText;
myText.SetStatus(Busy);
cout << myText.getStatus() << endl; //outputs 1, should output "Busy"
}

No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...