Is it possible to overload the output statement inside an enumeration? I get all kinds of errors (if I use a class, I don't get it):
../src/oop.cpp:18:2: error: expected identifier before 'friend'
../src/oop.cpp:18:2: error: expected '}' before 'friend'
../src/oop.cpp:18:2: error: 'friend' used outside of class
../src/oop.cpp:18:16: error: expected initializer before '&' token
../src/oop.cpp:22:1: error: expected declaration before '}' token
I need to implement something like this (java code):
public enum Type {
ACOUSTIC, ELECTRIC;
public String toString() {
switch(this) {
case ACOUSTIC: return "acoustic";
case ELECTRIC: return "electric";
default: return "unspecified";
}
}
}
Thank.
edit:
enum Type {
inline std::ostream& operator << (std::ostream& os, Type t)
{
}
};
source
share