Enum forward declaration in C++11
suggest changeScoped enumerations:
...
enum class Status; // Forward declaration; underlying type is int
Status doWork(); // Use the forward declaration
...
enum class Status { Invalid, Success, Fail };
Status doWork() // Full declaration required for implementation
{
return Status::Success;
}
Unscoped enumerations:
...
enum Status: int; // Forward declaration, explicit type required
Status doWork(); // Use the forward declaration
...
enum Status: int{ Invalid=0, Success, Fail }; // Must match the forward-declared type
static_assert( Success == 1, "" );
An in-depth multi-file example can be found here: Blind fruit merchant example
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents