Esempio:
typedef enum Color
{
RED,
GREEN,
BLUE
} Color;
void func(unsigned int& num)
{
num++;
}
int main()
{
Color clr = RED;
func(clr);
return 0;
}
Ottengo il seguente errore quando compilo questo:
<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);
^~~
Penso che la variabile ( clr) a cui passo func(unsigned int&)sia un lvalue. Posso ottenere l'indirizzo clre posso assegnargli un altro valore. Perché si trasforma in un valore quando provo a passarlo a func(unsigned int&)?
typedef enumnon sia un tipo nativo, e C ++ lo tratterebbe unsigned intdavvero come un tipo.
clr.
enum typefosse trattato come unsigned intin C ++.
enum Xè il suo tipo, distinto daint
enumaunsigned int?