I have the following code , which, it seems to me, should compile, but does not work.
#include <cstdint> typedef uint8_t testtype; enum testenum : uint8_t { }; void foo(uint8_t& v) {} int main() { testtype bar; foo(bar); testenum baz; foo(baz); return 0; }
I get the following error:
prog.cpp:15:9: error: invalid initialization of non-const reference of type 'uint8_t& {aka unsigned char&}' from an rvalue of type 'uint8_t {aka unsigned char}' foo(baz);
In my opinion, this should work because everything has the same base type (uint8_t). The typedef'ed variable can be passed to the foo function, but the enum (which has the uint8_t enum uint8_t ) cannot.
In my project, this means that I cannot pass all my enumerations into one overloaded function - it seems that I need to create an overload for every possible enumeration.
Is there an elegant way to get this for compilation, or do I need to pass enum through a second variable that I can pass by reference?
source share