Skip to main content
Filter by
Sorted by
Tagged with
4 votes
1 answer
2k views

I have a class defined as follows struct X { X() : data() {} int data; enum class Zzz : int { zero, one, two }; Zzz zzz; }; ... X xval; What is the value of xval.zzz - is undefined ...
uuu777's user avatar
  • 891
23 votes
6 answers
21k views

Since it's called a 'class' I would usually pass it as const reference, but if I use a plain enum it makes no difference, right? So does it make a difference if I pass an enum class as value or as ...
AutobahnPolizei's user avatar
0 votes
0 answers
341 views

I have some code with an enum class in it. I only want there to exist a single instance of this enum class. I am aware of singleton classes, but is there a way to make an enum class only visible from ...
user2138149's user avatar
  • 18.7k
7 votes
2 answers
1k views

I have the following class in C++11: class MyTable { public: enum class EntryType { USED, FREE }; MyTable(EntryType value) { for (uint32_t i = 0; i < 10; ++...
itzhaki's user avatar
  • 327
22 votes
3 answers
49k views

- Background Information: There is a class in C++11 known as enum class which you can store variables inside. However, I have only seen the type of the class to be char: enum class : char { v1 = '...
Agent 0's user avatar
  • 411
0 votes
2 answers
993 views

Disclaimer: Apologies if this question is too basic. I'm learning about Singleton and have a quick question its implementation, are these differences purely coding preferences or am I missing ...
Glaube's user avatar
  • 19
1 vote
1 answer
73 views

I want to create a class, that will be implicitly convertible to selected enum classes, in order to switch over it. But following code does not compile (gcc). Compiler complains that conversion is ...
omicronns's user avatar
  • 357
0 votes
1 answer
818 views

I want to use C++11 enum class as bitfields and find a nice approach here. But I stuck, if my enum class declaration is not in global namespace but in custom namespace or inside of a class instead. E....
Joe's user avatar
  • 3,190
3 votes
2 answers
15k views

I am trying to std::map, with an enum class and a std::string but I am getting some error. I am using gcc 4.4.7 with -std=c++0x (this is fixed) At .h file: enum class state_t{ unknown, off, ...
user2357667's user avatar
-1 votes
1 answer
403 views

When using a scoped enum in a varargs context, it is defined to be passed as its underlying type, as answered in "Can I use enum class values as arguments to varargs functions?" As I understand it, ...
Toby Speight's user avatar
  • 32.3k
8 votes
2 answers
1k views

Why and how does this work? What type is 'auto' here? auto lambda = [](){ enum class Local { X=0 }; return Local::X; }; auto x = lambda(); // No error! Why and what type is auto in this ...
cwschmidt's user avatar
  • 1,204
4 votes
1 answer
4k views

I have delegate component in a separate qml file, in which I'd like to have a property which is an enum class type coming from a c++ QObject. Is this possible? Here is a Minimum (non)Working Example: ...
speter's user avatar
  • 49
0 votes
0 answers
70 views

I have a class with an attribute type of a custom enum class Class::Type. Currently the declaration of Class looks like this: class Class { enum class Type { a, b, c, ...
user6245072's user avatar
  • 2,199
0 votes
1 answer
144 views

I want to print my Car object's color and noise. I'm trying to use c++11's enum class within my Car class. When I compile I get error Car::Color and Car::Noise is not a class, namespace, or scoped ...
user6333082's user avatar
2 votes
1 answer
3k views

lvl is an enum class. switch(lvl) { case LogLevel::Trace: return "Trace"; case LogLevel::Debug: return "Debug"; case LogLevel::Info: return "Info"; case LogLevel::Warning: return "...
SF.'s user avatar
  • 14.1k
3 votes
1 answer
4k views

How can I serialize/deserialize a class that has a member of enum class using boost serialization. Example: enum class enum_class{ item1=0,item2=1 } class foo{ private: friend class boost::...
Humam Helfawi's user avatar
0 votes
2 answers
982 views

I am writing a game in which there are 2 players, "BLACK" and "WHITE". I have the following enum class: enum class PlayerType { BLACK, WHITE }; I would like to write an ostream operator<< ...
user2138149's user avatar
  • 18.7k
1 vote
1 answer
407 views

If you define an operator << for a C++11 enum class, then you can use it successfully with Boost's unit test library. However if you put the enum class inside a namespace, the Boost code no ...
Malvineous's user avatar
  • 27.7k
3 votes
0 answers
58 views

Is there a way to use some kind of using directive to directly access members of an enum class type? enum class Foo { Foo1, Foo2, ... }; int main() { auto foo = Foo::Foo1; ??? // ...
Jan Rüegg's user avatar
  • 10.2k
0 votes
2 answers
261 views

I thought this should be easy, but I've been struggling with it for a while so I thought I should ask here. I want to make a template metafunction that takes a type corresponding to a C++11 enum ...
Chris Beck's user avatar
  • 16.4k
0 votes
2 answers
783 views

I've the following problem of which I cannot find a solution. Of course, it could be that a solution does not exist at all, but I'd like to have a try on SO before to give up. First of all, a snippet ...
skypjack's user avatar
  • 50.9k
1 vote
0 answers
162 views

I have recently migrated a Managed C++ project from Visual Studio 2010 to 2013. Inside the definition of a class, I have: static enum class ItemType { SHOP=IDS_SHOP, PAGE=IDS_PAGE, PHOTO=...
sergiol's user avatar
  • 4,365
3 votes
1 answer
384 views

What is the appropriate pattern for using enumerations as flags in modern C++? The question stems from my reading of the technical specification A Proposal to Add 2D Graphics Rendering and Display to ...
Escualo's user avatar
  • 42.5k
1 vote
1 answer
439 views

I am really strugling with an inheritance issue when using what should be strongly typed enums - however the enums seems to be ambigious when used through inheritance. Im using g++ (GCC) 4.7.2 enum ...
Tobibobi's user avatar
6 votes
1 answer
9k views

I want to use a unordered_map<std::pair<enum_class,other_enum_class>,std::uint8_t> for managing some pixelmap formats. Here the minimal code : #include <unordered_map> #include &...
coincoin's user avatar
  • 4,695
5 votes
1 answer
148 views

SSCCE: enum class confirm {yes}; struct item { confirm s:4; // (1) limiting storage size required }; int main() { item itm; itm.s = confirm::yes; // (2) OK switch (itm.s) { case ...
dyomas's user avatar
  • 740
1 vote
0 answers
480 views

I am working on my c++ library for microcontrollers and I need a way to specify different enum class content based on the template type. I have this code so far: #include <cstdint> #include &...
Erik Van Hamme's user avatar
1 vote
1 answer
215 views

I have the following C++11 code in my microcontroller project: template<std::uint32_t... I> struct mask_or; template<> struct mask_or<> { static constexpr std::uint32_t value = ...
Erik Van Hamme's user avatar
16 votes
4 answers
7k views

I am trying to wrap an enum class in a c++ header file for use in a cython project. For example, how can this enum class Color {red, green = 20, blue}; be wrapped with Cython.
user3684792's user avatar
  • 2,611
7 votes
5 answers
3k views

I have an enum class that I would like to use in my unit tests: enum class MyEnumClass { MyEntryA, MyEntryB }; I would like to use it as follows: MyEnumClass myEnumValue = MyEnumClass::...
ValarDohaeris-fuck-OpenAI's user avatar
4 votes
1 answer
182 views

I am increasingly finding scoped enums unwieldy to use. I am trying to write a set of function overloads including a template for scoped enums that sets/initializes a value by reference--something ...
Kyle Strand's user avatar
  • 16.5k
1 vote
1 answer
358 views

As far as I am aware at the moment it is not possible to do a typedef of the C++11 enum class. I would like to know if there is any other way I can reduce the length of the name of a variable enum ...
user avatar
0 votes
1 answer
138 views

Why this compiles in c++11: struct foo { enum class Resolution { None=10, Nominal=20 }; enum class Scale { None, Nominal }; }; while this doesn't: struct foo { enum Resolution { None=10, ...
Ruggero Turra's user avatar
0 votes
1 answer
575 views

When I try and reference an enum class from a test fixture, it fails to compile with error ./gtest_mcp23s17.cpp:25:52: error: no type named 'HW_ADDR_6' in 'mcp23s17::HardwareAddress' TC_mcp23s17 ...
Zak's user avatar
  • 12.7k
2 votes
1 answer
921 views

#include <iostream> #include <cassert> #include <type_traits> template<typename T> using Underlying = std::underlying_type_t<T>; enum class ETest : int { Zero = 0, ...
Vittorio Romeo's user avatar
7 votes
3 answers
12k views

The following code compiles and runs in Xcode 5 and in Visual Studio 2013. I am interested in trying out Codelite, but Codelite will not compile the following program (a problem since I am working ...
Matthew James Briggs's user avatar
1 vote
2 answers
163 views

while there are solutions to easily convert an enum to a string, I would like the extra safety benefits of using enum class. Is there a simple way to convert an enum class to a string? (The solution ...
Mike H-R's user avatar
  • 7,852
8 votes
4 answers
10k views

Why doesn't this code compile, and what can I do to make it compile? #include <iostream> using namespace std; enum class myEnum : unsigned int { bar = 3 }; int main() { // your code ...
paulm's user avatar
  • 5,962
0 votes
2 answers
74 views

MainClass.h: namespace Alpha{ enum class Parameters; } namespace Beta { enum class Parameters; } MainClass{ public: enum class Type{ Type_A, Type_B }; MainClass(const Type t); void DoStuff(...
shavera's user avatar
  • 853
5 votes
1 answer
963 views

Consider the following example: struct ConvertibleStruct {}; enum class ConvertibleEC {}; struct Target { // Implicit conversion constructors Target(ConvertibleStruct) {} Target(...
Clivest's user avatar
  • 499
6 votes
3 answers
12k views

What would be the right way to write an enum inside a class? I am writing conway's game of life code in c++. So i have a patterns class which contains the info about different kind of patterns: class ...
divine-code's user avatar
0 votes
0 answers
52 views

Suppose we have an enum class: enum class E { constant }; To refer to the enumerator in E, we can write E::constant, while the following is illegal: E e; e.constant; But consider this: struct S ...
Jamboree's user avatar
  • 5,349
1 vote
0 answers
259 views

Is there a way of getting Astyle to indent enum class elements to the same depth? I am getting the following: enum class test { test1 = 1, test2 = 2, test3 = 3, ...
John's user avatar
  • 12.1k
20 votes
3 answers
18k views

Is there a way to use Q_DECLARE_METATYPE() with enum class types? I know old enums work but what about these new, strongly typed, ones? Can't find anything regarding this problem elsewhere. I'm using ...
Venom's user avatar
  • 1,047
31 votes
6 answers
10k views

In C++11 we can cast a strongly-typed enum (enum class) to its underlying type. But it seems we cannot cast a pointer to the same: enum class MyEnum : int {}; int main() { MyEnum me; int iv = ...
John Zwinck's user avatar
9 votes
2 answers
2k views

Let's say I have enum class Flags : std::uint16_t { None = 0, A = 0x0001, B = 0x0002, C = 0x0004 } inline Flags operator|(Flags lhs, Flags rhs) { return static_cast<...
Billy ONeal's user avatar
7 votes
2 answers
5k views

I have a problem with enum classes, QVariants and the QSettings class. There are enum class values that I want to store within a QVariant which goes into a QSettings instance. So, my code actually ...
CppChris's user avatar
  • 1,281
6 votes
2 answers
2k views

enumeration cannot be a template is the error given when I try to compile with BCC64 (based on Clang) the following code: template <typename T> enum class fooEnum : T { a,b,c,d,e }; At ...
PaperBirdMaster's user avatar
9 votes
1 answer
1k views

I have a discrepancy between the behaviour of g++ 4.8.1 and clang++ 3.4. I've got a class A, of literal type, that has an explicit constexpr conversion function to type enum class E. Gcc allows me ...
je4d's user avatar
  • 7,878
5 votes
1 answer
9k views

enum class pid { Alpha, Beta, Gamma }; int main() { int propId = 2; switch(propId) { case pid::Alpha: case pid::Beta: case pid::Gamma: break; } } Above snippet ...
kozmo's user avatar
  • 51