Reputation: 83
I would kindly ask someone to explain me a bit why an enum can only be passed by right reference and not as simple reference ?
namespace n1
{
enum e1
{
f = 1,
f1
};
}
void f(n1::e1&& e)
{
std::cout<<static_cast<int>(e);
}
int main()
{
f(n1::e1::f1);
return 0;
}
Upvotes: 1
Views: 58
Reputation: 100
Enumerations are integral constants :
Remark : you don't have to cast the enum to print his value
void f(const n1::e1& e) {
std::cout<< e ;
}
Upvotes: 0
Reputation: 117298
enum
s are constants so you can't take it as n1::e1&
but as const n1::e1&
:
void f(const n1::e1& e) {
std::cout<<static_cast<int>(e);
}
Upvotes: 3