C++ enum class vs enum
I’d read about enum class in C++. It’s a slight strengthening of the compiler checking compared to plain old enums. Why you may wonder? Well,
- Conventional enums can implicitly convert to int, causing errors when someone does not want an enumeration to act as an integer.
- Conventional enums export their enumerators to the surrounding scope, causing name space pollution.
- The underlying type of an
enumcannot be specified, causing confusion, compatibility problems, and makes forward declaration impossible.
Additionally you can declare the underlying storage type, which lets the compiler catch bugs where a value is too large for the storage. Here’s a made up example to show this:
enum class byteThings : unsigned char {
Thing1 = 0x01,
Thing2 = 0x02,
Thing3 = 0x04,
BigThing = 0x120 // Compiler will complain!
}
The downside is that to get the int value, you now need to do a static cast but it does make your code safer.
byteThings b = Thing2;
int i= static_cast(thing); // 2
This is a screenshot of it as it stands and yes those asteroids are moving! It looks identical to the C version; the only difference is the code, not the appearance.
I got my Pi 4 a week ago and have been doing experiments on it with my Asteroids game. If I disable the line of code that kills the player ship in the DestroyObject() function and just add a return after case tPlayer: and uncomment the code that adds Asteroids when you press A then I can have lots of asteroids on screen. Also set the MAXASTEROIDS #define to 128.
I was interested in seeing what frame rate I got out of it and how much it warmed the PI.
As always bugs are the fault of the creator and mea culpa (my bad!). I can trace this back to my conversion from the Windows source to the Ubuntu version. This line in LoadMask
I made the mistake of starting by trying to convert the final version of Asteroid; all 2,200 lines of C into C++.
Reading the temperature of a Raspberry PI can be done in a couple of ways. This command: