Enum in C++

C++11 introduced a much better enumeration. It provides a named scope for its enumerators and is strongly typed:

enum class FileType
{
    Png,
    Jpg,
    Bmp
};

write_file(img_data, "foo", FileType::Jpg);

When using an older C++ compiler, I try to get the scope feature of C++11 by using a namespace:

namespace FileType
{
    enum Enum
    {
        Png,
        Jpg,
        Bmp
    };
}

// Excepts the type FileType::Enum
write_file(img_data, "foo", FileType::Jpg);
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s