As Jerry said, it's not possible directly. One way to solve this is to have two enums. One for the category, and one for the sub-category.
However, as georgesl said, it probably can be dangerous to do this in a protocol. You definitely should explicitely define the enum values:
struct Error { enum Type { UNKNOWNTYPE = 0, TYPE1 = 1, TYPE2 = 2, TYPE3 = 3 }; enum Subtype { UNKNOWNSUBTYPE = 0, // subtype for error type 1 CAUSE1 = 1001, CAUSE2 = 1002, CAUSE3 = 1003, // subtype for error type 2 CAUSE4 = 2001, CAUSE5 = 2002 }; Type type; Subtype subtype; }; int main() { Error error; error.type = Error::TYPE1; error.subtype = Error::CAUSE1; }
Make sure to choose the numbers wisely for future extensions.
Update: made the example actually work.
Alternative, more typesafe solution:
struct ErrorType { enum type { UNKNOWNTYPE = 0, TYPE1 = 1, TYPE2 = 2, TYPE3 = 3 }; }; struct ErrorSubtype { enum type { UNKNOWNSUBTYPE = 0, // subtype for error type 1 CAUSE1 = 1001, CAUSE2 = 1002, CAUSE3 = 1003, // subtype for error type 2 CAUSE4 = 2001, CAUSE5 = 2002 }; }; struct Error { ErrorType::type type; ErrorSubtype::type subtype; }; int main() { Error error; error.type = ErrorType::TYPE1; error.subtype = ErrorSubtype::CAUSE1; }