aantron / better-enums

C++ compile-time enum to string, iteration, in a single header file
http://aantron.github.io/better-enums
BSD 2-Clause "Simplified" License
1.67k stars 173 forks source link

Class Initializelist (on constructor) compile error #33

Closed scahp closed 5 years ago

scahp commented 7 years ago

Hi, I have met a problem to use BetterEnums in class. This is sample code.

BETTER_ENUM(EnumTest, uint32, NONE = 0, APPLE)

class Apple { public: Apple() : test(EnumTest::APPLE) {} Apple(int k) {} EnumTest test; };


consoleapplication1.cpp(32): error C2248: 'EnumTest::EnumTest': cannot access private member declared in class 'EnumTest' consoleapplication1.cpp(26): note: see declaration of 'EnumTest::EnumTest' consoleapplication1.cpp(26): note: see declaration of 'EnumTest'

I could solve this problem by this code.

BETTER_ENUM(EnumTest, uint32, NONE = 0, APPLE)

class Apple { public: Apple() : test(EnumTest::APPLE) {} Apple(int k) : test(EnumTest::APPLE) {} EnumTest test; };

or

class Apple { public: Apple() {} Apple(int k) {} EnumTest test = EnumTest::APPLE; };

Thanks.

FlorianWolters commented 7 years ago

It's by intention, refer to http://aantron.github.io/better-enums/tutorial/ScopeAndSafety.html#DefaultConstructor. This link describes how-to change the default behavior.