Overriding a property ?
Lucien via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Apr 14 13:54:38 PDT 2016
On Thursday, 14 April 2016 at 20:39:50 UTC, Steven Schveighoffer
wrote:
> On 4/14/16 4:21 PM, Lucien wrote:
>> How can I override a property ?
>>
>> Test code:
>> ----------------------------
>> class A
>> {
>> @property bool foo { return false; }
>
> This isn't valid, you need parentheses for foo. This doesn't
> compile does it?
>
>> void myFunc() { ... }
>> }
>>
>> class B : A
>> {
>> override bool foo { return true; } // error
>
> Same thing here.
>
>> override void myFunc() { ... }
>> }
>> ----------------------------
>> Output error:
>> function B.foo return type inference is not supported if may
>> override
>> base class function.
>
> This has to do with type inference. Did you not specify bool in
> your original?
>
> If I put parens on both foo, then it compiles for me.
>
> -Steve
You're right.
In fact it didn't work because I did:
----------------------------
class A
{
@property foo() { return false; }
void myFunc() { }
}
class B : A
{
override @property foo() { return true; } // error
override void myFunc() { }
}
----------------------------
When I remove the bool, the program compile but show the error
when overriding.
Is it a bug ?
More information about the Digitalmars-d-learn
mailing list