My class has a private enum whose members are being used to index an array of strings, the output of which is written to an output stream.
private:
enum supportedMessageTypes(CRITICAL = 0, WARNING, INFORMATION);
string messages[3];
//meanwhile, inside the constructor,
messages[3] = {"Critical error message",
"Warning message",
"Information message"};
Since I'm going to be using the enum values around my code a lot, I'd like to be able to overload operator<< to perform a lookup of the enum value, match it to the corresponding string in the array, and return that in the following manner:
cout << CRITICAL << ": " << messageText << std::endl;
The problem I have is that supportedMessageTypes is private while overloading of operator<< should be done as a non-member function. I know I can define a friend function that overloads operator<< for my class, but I'm simply not comfortable with breaking encapsulation in that way, and was wondering if anyone knew of a way to overload operator<< without using friend functions or making supportedMessageTypes public?