According to the following program, I can understand that, const keyword at a front of a references means Const Reference to const value, correct?
#include <iostream>
using namespace std;
struct s
{
int x;
};
int main(void)
{
s a = {10}, b = {30};
// IN POINTERS ----------------
const s* ptrToConstValue;
ptrToConstValue= &a;
//ptrToConstValue->x = 30;
ptrToConstValue = &b;
s* const constPtrToNonConstVaue = &a;
constPtrToNonConstVaue->x = 40;
//constPtrToNonConstVaue = &b;
const s* const constPtrToConstValue = &a;
//constPtrToConstValue = &b;
//constPtrToConstValue->x = 30;
// IN REFERENCES -------------
const s& seemsToBeConstRefToConstValue = a;
//s = b;
//s.x = 30;
return 0;
}
References are always const, so you don’t need the
constkeyword forthem; it is, in fact, forbidden.
So you have:
, but only:
The
constwhich immediately follows the name of the type can be movedto the beginning of the declaration, at the cost of some confusion to
the reader.