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 13:36:56 UTC 2022


```d
import std;

class Test
{
     float[3] _position = [0,0,0];
     float[3] position()
     {
         writeln("Get");
         return _position;
     }
     float[3] position(float[3] value)
     {
         writeln("Set");
         return _position = value;
     }
}

class STest : Test
{
     float[3] position;
}

void main()
{
     STest t = new STest;
     t.position = [1,2,3];
}
```

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


More information about the Digitalmars-d mailing list