Why isn't that a compilation error? - define a variable in a subclass with the same name of a superclass method

Hipreme msnmancini at hotmail.com
Thu Nov 10 15:02:59 UTC 2022


On Thursday, 10 November 2022 at 14:30:30 UTC, Steven 
Schveighoffer wrote:
> On 11/10/22 8:36 AM, Hipreme wrote:
>
>> It basically ignores the old method to just use the new 
>> variable.
>> 
>> If I try:
>> ```d
>> t.position([1,2,3]);
>> ```
>> I get the error: onlineapp.d(26): Error: function expected 
>> before `()`, not `t.position` of type `float[3]`
>> 
>> There's something really misleading
>
> When you derive a type, and override a name, the old name is 
> masked or hidden. You can alias the original name in, but I 
> don't think it would work for overloading a field with a 
> function.
>
> -Steve

That could trigger an error or at least a warning, just silently 
hiding that can lead to bugs


More information about the Digitalmars-d mailing list