enum class is not a class unless it’s -std=c++11

treestuff

As I progress through the C++ course at Udemy, I’ve just completed section 4. However, I ran into a few snags along the way. Some of them are due to differences between the instructor using Windows, and me using Linux. Most notably, I ran into a complete showstopper that took me a while to figure out, so I’ll share it here.

g++ -Wall -c “Timber.cpp”
Timber.cpp:17:1: warning: scoped enums only available with -std=c++11 or -std=gnu++11
enum class side { LEFT, RIGHT, NONE };
^
Timber.cpp: In function ‘int main()’:
Timber.cpp:169:20: error: ‘side’ is not a class or namespace
side playerSide = side::LEFT;
^
Timber.cpp:264:26: error: ‘side’ is not a class or namespace
branchPositions[i] = side::NONE;
^
Timber.cpp:287:18: error: ‘side’ is not a class or namespace
playerSide = side::RIGHT;
^
Timber.cpp:321:18: error: ‘side’ is not a class or namespace
playerSide = side::LEFT;
^
Timber.cpp:534:31: error: ‘side’ is not a class or namespace
if (branchPositions[i] == side::LEFT)
^
Timber.cpp:542:36: error: ‘side’ is not a class or namespace
else if (branchPositions[i] == side::RIGHT)
^
Timber.cpp: In function ‘void updateBranches(int)’:
Timber.cpp:688:24: error: ‘side’ is not a class or namespace
branchPositions[0] = side::LEFT;
^
Timber.cpp:692:24: error: ‘side’ is not a class or namespace
branchPositions[0] = side::RIGHT;
^
Timber.cpp:696:24: error: ‘side’ is not a class or namespace
branchPositions[0] = side::NONE;
^
Compilation failed.

Per the instructor, I typed out the branches (literally, tree branches) and I get this odd error about the enum class side not being a class or namespace. The key was this portion:

warning: scoped enums only available with -std=c++11 or -std=gnu++11

A Google search and a bit of perusing lead me to change my build script to this:

#!/bin/bash

# You need libsfml installed on your system!

g++ -c -std=c++11 Timber.cpp
g++ Timber.o -o timber-app -lsfml-graphics -lsfml-window -lsfml-system

./timber-app

echo “type ./timber-app to launch”
exit

In order to get it to compile, I had to declare the -std=c++11 during the build. I added it to my Geany program as well, under the settings.

geany11

Now it compiles without issue! So far, I’ve only added some bushy branches to my game, but it is coming along nicely! You can check it out at my GitLab if you’d like.

Linux – keep it simple.

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s