lundi 30 décembre 2019

Why a enum variable is a rvalue here?

I make a sample code below:

typedef enum Color
{
    RED,
    GREEN,
    BLUE
} Color;

void func(unsigned int& num)
{
    num++;
}

int main()
{
    Color clr = RED;
    func(clr);
    return 0;
}

I get following error when I compile it:

<source>: In function 'int main()':

<source>:16:9: error: cannot bind non-const lvalue reference of type 'unsigned int&' to an rvalue of type 'unsigned int'

     func(clr);

         ^~~

I think, the variable (clr) I pass to func(unsigned int&) is a lvalue, I can get the address of clr and can assign another value to it. Why it turns into an rvalue when I try to pass it to func(unsigned int&)?

Aucun commentaire:

Enregistrer un commentaire