Overloading const member function

Nub Public nubpublic at gmail.com
Thu Jun 23 01:22:03 PDT 2011


On 6/23/2011 4:14 PM, Daniel Gibson wrote:
> Am 23.06.2011 10:11, schrieb Nub Public:
>> Why doesn't overloading of const member functions work?
>>
>> struct S {
>>      int a, b;
>>
>>      int A() const { return a; }
>>      ref int A() { return a; }
>>
>>      int min() const { return A()<  b ? A() : b; }
>> }
>>
>> DMD2 compiler error: S.A () is not callable using argument types () const
>>
>> Is it a bug or by design?
>
> how do you want to call the different A() functions? i.e. how will D
> know which one you want to call?

It would depend on whether the instance of the struct is mutable or not.

eg. the min() function is const, so the this object is const, and it 
would resolve to calling A() const.


More information about the Digitalmars-d mailing list