hiding a class property behind a method
Ali Çehreli
acehreli at yahoo.com
Sat Feb 22 12:43:09 PST 2014
On 02/22/2014 10:00 AM, Maxim Fomin wrote:
> On Saturday, 22 February 2014 at 17:41:58 UTC, Ali Çehreli wrote:
>>
>> The code uses the two objects through the A interface and x() is a
>> virtual function on that interface.
>>
>> When the C interface is used then we get C.x, which happens to be
>> hiding the x() function of the base class.
Sorry. I meant "If the C interface is used", not "When the".
>>
>> It looks normal to me.
>>
>> Ali
>
> Spec is silent on this, so this is indeed a question.
>
> Actually A is not interface, so I don't understand why you mention it.
I did not mean D's feature 'interface'. The code explicitly specifies
the objects as As, comitting to A's class interface. (As in, every used
defined type defines an interface.)
> And there is neither 'taking C interface' because static type is A, so A
> function is called, neither it hides function of the base class because
> it is base class function which is called. I don't understand you
> completely.
I agree with all of that.
> since there is no function, base class
> virtual is not replaced, so virtual table of C looks like A, so A member
> function is called.
Exactly. Otherwise, when faced with such a situation the compiler would
have to synthesize a virtual function for C's virtual table.
string x()
{
return member_x;
}
> so it appears that data member have priority over function.
It looks like name hiding, which I am familiar from C++. Name hiding
does not differentiate between functions and variables.
Ali
More information about the Digitalmars-d-learn
mailing list