B
B
Bogdan2018-11-02 11:03:31
Cross-platform
Bogdan, 2018-11-02 11:03:31

Enum forward declaration - how to get the base type?

There is a *.h file in which you need to make a forward declaration enum (not an enum class).
The first thing that comes to mind:
enum myEnum : int;
This works, but it's not entirely correct in cross-platform (Win 64 msvc, Linux 64 gcc) code to explicitly specify the data type explicitly (in the header that we forward, there is no way to specify the enum data type of the day, there is C ++ 03)
Therefore, the second, what comes to mind:

#include <type_traits>
enum enum_dummy { }
enum myEnum : std::underlying_type_t<enum_dummy>;

But gcc doesn't understand what I want to do.
Is there a good way out of this situation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Bogdan, 2018-11-02
@4elovek37

The problem turned out to be not in gcc, but in crooked hands :) This is how it compiles:

enum enum_dummy {  };
enum myEnum : std::underlying_type<enum_dummy>::type;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question