In c++, a reference variable can refer to an object as below
int i;
int &ref = i;
BUT if we put "const" keyword it can take any value, may be some variable or constant value.
Could some one brief me on this?
Regards, Abhineet
In c++, a reference variable can refer to an object as below
int i;
int &ref = i;
BUT if we put "const" keyword it can take any value, may be some variable or constant value.
Could some one brief me on this?
Regards, Abhineet
This is known as const
-correctness.
The standard does not define any implicit conversions from cv-qualified to less qualified types, and references act mostly like pointers which can only be assigned once and dereference automatically(Though you cannot bind a non-const lvalue to a non-const reference).
Still, you can use const_cast
to override the compiler. On your own head be it then.