Help Please!!!

Pages: 12
I dont quite understand the part in the Note, (still dont understand the reference part)

If to return to my example then consider lines

   A a1;
   a1.f(); // void f() is called
   // other lines are skipped
   const A &ra = a1;
   ra.f(); // void f() const is called 

Here object a1 is defined as non-const while reference ra is defined as const. Reference ra refers object a1. It is a const reference (JLBorges calls it utter nonsense:)). So you may not to call non-const methods of object a1 through const reference ra. The compiler in this case considers underlaying object as a const object that is it restricts access to the underlying object allowing to use only const methods. The object itself is non-const as before.

Last edited on
A reference is inherently const, so some semantic leeway is possible: when someone says const reference, one can interpret that the intent was to say reference to const.

A pointer is not necessarily const: when someone says const pointer, one can't interpret that the intent was to say pointer to const. A const pointer, and a pointer to const are distinct (and both are possible).

And when someone says
vlad from moscow wrote:
.... but if if an object is referenced by a const reference or a const pointer it can access only methods with the qualifier const.

one can only conclude that the person is talking through his or her hat.

If you have some difficulties in interpreting the term const reference widely used in the C++ Standard it is your problem. As any entity reference can be declared as const or non-const that is its declaration either contains the qualifier const or not. And when a declaration of a reference contains qualifier const it is called const reference.
As for the words const pointer I agree that there is some confusion. But usually it is clear from the context what these words mean.
In Wikipedia, even more than in real life, getting the Last Word in a debate is crucial
Getting the last word means that you win the debate. It also shows your moral superiority, and willingness to stand your ground. This should convince your opponent that you are correct, and will certainly impress your fellow Wikipedians.
It is particularly important to get the last word where you are in some doubts as to the merits of your case. The last word will serve as a clinching argument that will make up for any deficiencies in your logic.
How to get the last word
...We recommend the following tried and tested tactics to aid you in taking what is rightfully yours.
However, sometimes your opponent is well aware of this Wikipedian convention and will attempt to wrongfully deprive you of your right. Do not give ground to such intimidation. Pursue your case with fortitude and vigour. If your actual arguments have already been stated on the page, do not fear to repeat them in a slightly different form. CAPITALISING YOUR ARGUMENT, or bolding sections, can be used to give variety if you fear you are being repetitive. - Wiki
Let your quotation will be the Last Word.:)
Last edited on
Now that the discussion has advanced to various nuances of standards, I might as well ask:

Whose idea was it to include these two bad boys:
const int a = 1;
int const b = 1;
> Whose idea was it to include these two bad boys:


Pre-standard C and C++ imposed few (if any) ordering rules on specifiers.
I don't remember any deep thoughts or involved discussions about the order at the time.
The earliest (C or C++) code using "const" appears to have been created (by me)..
@vlad from moscow
But the thing is that I never declared any reference so why is the compiler saying that? Well whatever for now, I understand whats needed but any more information to further extend my understanding is definitely appreciated but not necessary.
Not explicitly. Attempting to call a non-const method implies that you should have non-const object.
Topic archived. No new replies allowed.
Pages: 12