Meaning of const
Ali Çehreli
acehreli at yahoo.com
Tue Jan 24 16:24:27 PST 2012
On 01/24/2012 04:06 PM, Jonathan M Davis wrote:
>> class A {
>> int x;
>>
>> const int f1() { ... }
>> int f2() const { ... }
>> const(int) f3() { ... }
>> }
>>
[...]
> int f2() const
>
> becomes
>
> int f2(const A this)
>
> Now, the confusing part is the fact that unlike C++, D allows you to
put the
> const for making the function on the _left-hand_ side of the function
(C++
> only lets you put it on the right).
Ok.
> So, while a C++ programmer expects that
>
> int f2() const
>
> means that f2 is const, they're likely to be surprised by the fact
that in
>
> const int f1()
>
> it's the int that's const, not f1.
Have you phrased that last bit correctly? :) It seems to conflict with
what you have said earlier.
f1() and f2() are the same thing in D.
Ali
More information about the Digitalmars-d-learn
mailing list