abstract base class and class members

David d at dav1d.de
Sun Mar 4 14:02:48 PST 2012


Am 04.03.2012 21:24, schrieb Jonathan M Davis:
> On Sunday, March 04, 2012 19:36:20 David wrote:
>> Am 04.03.2012 19:22, schrieb H. S. Teoh:
>>> On Sun, Mar 04, 2012 at 06:22:47PM +0100, Timon Gehr wrote:
>>>> On 03/04/2012 06:16 PM, David wrote:
>>>>> Is this intended behaviour? http://ideone.com/xrvvL
>>>>>
>>>>> shouldn't the 2nd writeln print the same as the first, well at least the
>>>>> same content of i?
>>>>
>>>> This is intended behaviour. You have two distinct definitions of i.
>>>> If you want to set i to 2 in the derived class, do so in the class
>>>> constructor.
>>>
>>> Yeah, only member functions can be overridden in the derived class (and
>>> even then, D requires you to explicitly state that with the 'override'
>>> keyword).
>>>
>>> Makes one wonder, though... from an OO perspective, does it make sense
>>> to have overridable non-function members? What semantics would (should)
>>> that have?
>>>
>>>
>>> T
>>
>> Thanks for your answers.
>>
>> Maybe we should also allow override for fields.
>
> Variables can't be polymorphic, and it wouldn't make sense for them to be.
> Overidding is done to change behavior.
>
> By the way, I wouldn't rely on much that ideone says about D at this point.
> It's still on version 2.042 of dmd, whereas the latest release is 2.058.
>
> - Jonathan M Davis
Sometimes you need constants which vary from the parents, which sould be 
statically accessable and which you can use to identify the class, I 
don't like the idea of having an additional functoion (@property) for 
doing this.

I used ideone just to show you, I discovered this on my PC with dmd 2.058


More information about the Digitalmars-d-learn mailing list