const and non-const member function

Kirk McDonald kirklin.mcdonald at gmail.com
Thu Jul 26 02:03:08 PDT 2007


Frits van Bommel wrote:
> Christian Kamm wrote:
>>> (I'm also not 100% pleased with the 'const R M(){}' syntax for declaring
>>> const methods...  
>>
>> Yes, it's quite bad:
>>
>> const Foo func(const Foo)
>> {
>>   const Foo = ...;
>> }
>>
>> All consts look the same, but the first means the method, the second 
>> is an
>> alternative for const(Foo) and the third is the compile-time const 
>> storage
>> class. I'd probably disallow const Foo in parameter declarations, yet 
>> don't know
>> how to do make the method-const look different.
> 
> How about this for method-const:
> ---
> Foo const(func)(const Foo) {
>     // ...
> }
> ---
> Though I guess that may look too much like the const(Type) notation...

I have a radical notion. We could place it after the parameter list!

Foo func(const Foo) const {
     // ...
}

-- 
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org


More information about the Digitalmars-d-learn mailing list