int const & refToConst = i; // OK
int & const constRef = i; // Error the "const" is redundant
what is the difference between the two ..?
int const & refToConst = i; // OK
int & const constRef = i; // Error the "const" is redundant
what is the difference between the two ..?
The first is a reference to const int, the object being referenced is const. The second is a const reference to int, the reference itself is const. However, a const reference is nonsensical because references are permanently bound to a single object on definition. To have a const reference implies that you could rebind the reference to another object, which is not allowed.
Such is also true to pointers. const char * constantData;
char * const constantPointer;
const char * const constantAll;
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.