Minor: enum qualifiers in C++ are non-standard

This just a note to anyone who plans to move outside Visual Studio someday into more standard C++ (especially cross-platform). It turns out that Visual Studio allows certain syntax as language extensions, which is not standard and won’t work with other compilers. One of these is the enum qualifier.

The video passes the ECC_PhysicsBody to the object query params as ECollisionChannel::ECC_PhysicsBody, using the enum type as a qualifier. This will not compile if using a standard-compliant compiler. (A common way to qualify enum values is to put the enum in a class or namespace.) It happens to work in Visual Studio, thanks to Microsoft.

It won’t matter much for this course, but I wanted to mention it just in case, so that certain bad habits don’t develop that can lead to grief down the road. :slight_smile:

Doesn’t have anything to do with Microsoft, this should compile on any compiler because

FCollisionObjectQueryParams(ECollisionChannel QueryChannel)

is an overloaded constructor. And here’s a test case to prove such thing would compile on gcc and clang.

https://godbolt.org/g/bMfqjo

Using your setup, if you use this line:

Bar(ECollisionChannel::ECC_PhysicsBody);

it will fail to compile with gcc prior to gcc 6.0 (which is where my experience lies). So it looks like gcc has changed.

And if I try clang, I get this interesting warning:

!!warning: use of enumeration in a nested name specifier is a C++11 extension [-Wc++11-extensions]

And it won’t compile at all with clang before 3.7. So it looks like the standard has updated as well.

(Basically, it looks like I am incorrect, at least as far as more modern compilers go.)

Based on that warning it looks like it was added to the standard in C++11. Which I guess makes sense considering scoped enums (enum class) was added to the standard.

Privacy & Terms