Skip to main content
Filter by
Sorted by
Tagged with
2 votes
3 answers
175 views

The C++ Coding guidelines, Enum.3: Prefer class enums over “plain” enums contains following example: void Print_color(int color); enum Web_color { red = 0xFF0000, green = 0x00FF00, blue = 0x0000FF }; ...
Erik Man's user avatar
  • 874
29 votes
1 answer
2k views

The std::align_val_t type is defined as: namespace std { enum class align_val_t : size_t { }; } What is the purpose of such an empty enumeration? What's the difference with a typedef?
Oodini's user avatar
  • 1,463
-1 votes
2 answers
71 views

I have an enum class, say enum class color { Red, Green, Blue, /* etc. */}; and I have class template, template <color Color> class foo; Now, I want to declare a data type which holds, for ...
einpoklum's user avatar
  • 137k
0 votes
0 answers
86 views

I learned to use enum class to constantize the constants involved. I also learned that using when when using enum class is very effective. I think I heard that you may not use else. Case1 may not use ...
HyeonBae Ji's user avatar
1 vote
1 answer
100 views

I have the following code: logging.hxx #include <iostream> #include <string> #include <sstream> #include "singleton.hxx" #include "utils.hxx" class FGaugeLogger:...
TheEagle's user avatar
  • 6,005
0 votes
2 answers
194 views

More precisely, the feature I want is like implicitly convert an enum to its subset enum and vice versa. The code I wish it working: enum class Human { A = 1, B = 2, }; enum class Male { //...
ke_bitter's user avatar
5 votes
2 answers
304 views

In C++ I basically have two choices in policy based design patterns: I can use individual types (based on which an overload is selected) or specify an enum that contains all policies and I would ...
glades's user avatar
  • 5,356
1 vote
1 answer
152 views

I'm reviewing a lot of code where I need to ensure there are no static_cast (or any cast) calls on variables that could be out of range of the enum class that is being cast to. Ideally I'd be able to ...
GLJeff's user avatar
  • 147
3 votes
2 answers
519 views

I've been using overloaded operators as demonstrated in the second answer from here: How to use C++11 enum class for flags ... example: #define ENUMFLAGOPS(EnumName)\ [[nodiscard]] __forceinline ...
GLJeff's user avatar
  • 147
0 votes
0 answers
27 views

I observed some behavior relating to enum structs and compound operators that I don't understand (yet). When using an enum struct as a flag, I'd like to write stuff like flag &= enum_name::What. ...
rochus's user avatar
  • 1
2 votes
3 answers
1k views

I am writing a c wrapper around a c++ library. In the c++ there are enum classes used as types for function arguments. How do I use theme correctly in the c header. One ugly way would be to use int's ...
ludw's user avatar
  • 123
5 votes
3 answers
1k views

I have an enum type in my code, like this: enum class GameConsts: size_t { NUM_GHOSTS = 4 }; I find myself repeating the required static_cast to get the enum value: Ghost ghosts[static_cast<size_t&...
Amir Kirsh's user avatar
  • 14.4k
0 votes
1 answer
22 views

Old code: typedef enum tagUndoAction { UNDO_CHANGE_CELL = 0, UNDO_CHANGE_SELECTION_START, UNDO_CHANGE_SELECTION_SUB } UNDO_ACTION_E; New code:...
Andrew Truckle's user avatar
2 votes
4 answers
717 views

I've been working with C++ on a Time class in Qt and I need to write an enum class that contains the formats that I use in showTime(). Because of the nature of the QString formats I've been getting ...
Gio Formichella's user avatar
3 votes
1 answer
870 views

Here is a small code in which the conflict occurs. is there any way to get around this correctly? #define DEBUG 0 enum class TypeEnum : int { DEBUG = 0, INFO = 1 };
Олег Привалов's user avatar
7 votes
3 answers
1k views

I searched a bit here on SO and was surprise that I didn't find any similar question. Happy for any hints in case this has already been answered. I have a codebase with a lot of enum classes defined. ...
PluginPenguin's user avatar
0 votes
0 answers
164 views

To convert a strongly-typed enum to int we can use: enum class MyEnum { a, b }; int x = static_cast<int>(MyEnum::a); what if i use the following line, which is shorter: int x = int(MyEnum::a); ...
qwa's user avatar
  • 143
0 votes
2 answers
1k views

I have a function to change the state of an LED that takes in an enum argument with three possible values: enum class Command { Off, On, Toggle }; void led(Command); I'd like to be able to use the ...
Cameron Tacklind's user avatar
0 votes
2 answers
2k views

Getting error while trying to print the enum class object. I am getting the error while trying to print this. where am I doing mistake? #include <iostream> using namespace std; int main() { ...
Suneeldatta Kolipakula's user avatar
3 votes
2 answers
7k views

What is the difference between the Enum and Enum Class and how to converting Enum value to the integer in "Enum" and "Enum Class"?
Mohammad reza Kashi's user avatar
0 votes
0 answers
184 views

Say I have a enum class foo : std::uint32_t { a = 4711, b = 815, ... }; with n enumeration constants. Assume that there actual numerical value is important. I need to pass precisely one ...
0xbadf00d's user avatar
  • 18.4k
0 votes
1 answer
72 views

I'm coding in a C++ project that hasn't advanced beyond C++11 yet. Let's say I have an enum class as follows: enum class Weekdays { kSunday = 0, kMonday, ... kSaturday, }; I want to ...
Dragon s Den's user avatar
4 votes
3 answers
1k views

I have a piece of code that returns the value of some bits of a given number (I counted enum classes as a number too, using a static_cast). template<typename Type> bool get_bits(Type input, ...
s4eed's user avatar
  • 8,041
3 votes
4 answers
11k views

I wanted to change an old-style enum to enum class : int because of its own scope. But the compiler complains about using the values in integer arithmetics. But why - since the enum is explicitly ...
vlad_tepesch's user avatar
  • 7,027
8 votes
1 answer
808 views

I have an event handler class that uses a template argument to set the event type. I want to enforce these event types to be enum classes of one byte size. Static assertion against the size is not an ...
Smartskaft2's user avatar