Enum forward declaration in C++ 11

suggest change

Scoped enumerations:

...
enum class Status; // Forward declaration 
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 forward declare type
static_assert( Success == 1 );

An in-depth multi-file example can be found here: Blind fruit merchant example

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents