C++11 type- and scope-safe enumerations a.k.a "enum class" types. This tag should be used when asking a question specifically related to scoped enums such as, but not limited to, overloading the increment, decrement, or bitwise operators.
Questions tagged [scoped-enums]
9 questions
8
votes
0 answers
Accessing scoped enumerators via class member access operator
Sample unit:
struct Supercalifragilisticexpialidocious
{
enum class Frob
{
Foo, Bar, Baz, Qux
};
Frob frob;
};
Supercalifragilisticexpialidocious maker();
void f()
{
auto g = maker();
// Allowed?
if ( g.frob…

M.M
- 138,810
- 21
- 208
- 365
7
votes
2 answers
C++: Cannot initialize enum value from a constant of the same type
For unknown reason I cannot initialize enum value from a constexpr value. Here is my code:
enum class Enum: unsigned int; //Forward declaration
constexpr Enum constant = static_cast(2);
enum class Enum: unsigned int {
A = 0,
B = 1,
C =…

Anton Sukhinov
- 158
- 1
- 8
1
vote
1 answer
How to use the `using` keyword in gcc 10.4?
I am compiling with the C-Stadard 20 using this argument: "-std=gnu++2a". Thus I thought I am able to use the using keyword as following:
void anyfunc(const foo::bar& value) {
switch (foo:bar(value)) {
using enum foo:bar;
case…

eDeviser
- 1,605
- 2
- 17
- 44
1
vote
2 answers
How to map different C++ classes to enum class values
I produce messages and each is receive by one object, chosen by an enum class member:
enum class ReceiverID
{
R1,
R2,
MAX_NUM_RECEIVERS
};
struct Msg
{
ReceiverID _receiverID;
Data _data;
};
The receiving classes are stored in…

user997112
- 29,025
- 43
- 182
- 361
1
vote
1 answer
Refactoring scoped enum bitwise operator code duplication
I have several scoped enums that can be used as bitwise flags. I've implemented the bitwise operator overloads identically for every type as exampled here:
ScopedEnumFoo& operator|=(ScopedEnumFoo& a, const ScopedEnumFoo& b) noexcept {
using…

Casey
- 10,297
- 11
- 59
- 88
0
votes
1 answer
Forcing usage of one alias of an enum c++
I want to give an enum multiple aliases, but force the calling code to use one specific alias when passing an enum value to a specific class. Here's my bright idea, which doesn't work:
template
struct MoreDifferentS : Stype…

lequinne
- 118
- 8
0
votes
2 answers
About the value of a scoped enum containing a value of the underlying type that does not correspond to any of the enumerators
Basically, given
enum class Color : int { R, G, B };
Color c;
is there any way for c to end up holding something other than R, G, B? Or, in other words, an underlying int other than 0, 1, or 2?
I know that the declaration of c above leaves it…

Enlico
- 23,259
- 6
- 48
- 102
0
votes
0 answers
Unable to Intialize Enum Class Types | Visual C++
Consider an enum class
enum class FOO
{
A,B,C
};
struct something
{
FOO abc = FOO::A; //Compiler Doesnt like this
}
int main(){
something _something;
return 0;
}
So the compiler doesnt like the initialisation and gives me 3 different…

inpinseptipin
- 1
- 2
0
votes
1 answer
Compile error initializing struct member with enum class
Following program giving compilation error as following
// Example program
#include
#include
enum class Animation: int{
Hide=0,
Show,
Flicker
};
struct Icon {
int id;
char name[10];
Animation currentAnim;
…

rakibdana
- 39
- 1
- 6