digitalmars.D.learn - Overriding a property ?
- Lucien (18/18) Apr 14 2016 How can I override a property ?
- Satoshi (12/30) Apr 14 2016 try
- Steven Schveighoffer (8/25) Apr 14 2016 This isn't valid, you need parentheses for foo. This doesn't compile
- Lucien (19/47) Apr 14 2016 You're right.
- Steven Schveighoffer (8/25) Apr 14 2016 Hm... I don't know. the error specifically says it's not supported. But
How can I override a property ? Test code: ---------------------------- class A { property bool foo { return false; } void myFunc() { ... } } class B : A { override bool foo { return true; } // error override void myFunc() { ... } } ---------------------------- Output error: function B.foo return type inference is not supported if may override base class function. Any ideas ?
Apr 14 2016
On Thursday, 14 April 2016 at 20:21:38 UTC, Lucien wrote:How can I override a property ? Test code: ---------------------------- class A { property bool foo { return false; } void myFunc() { ... } } class B : A { override bool foo { return true; } // error override void myFunc() { ... } } ---------------------------- Output error: function B.foo return type inference is not supported if may override base class function. Any ideas ?try class A { property bool foo() { return false; } void myFunc() { ... } } class B : A { override property bool foo() { return true; } // error override void myFunc() { ... } }
Apr 14 2016
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; } // errorSame 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
Apr 14 2016
On Thursday, 14 April 2016 at 20:39:50 UTC, Steven Schveighoffer wrote:On 4/14/16 4:21 PM, Lucien wrote: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 ?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; } // errorSame 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
Apr 14 2016
On 4/14/16 4:54 PM, Lucien wrote: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 ?Hm... I don't know. the error specifically says it's not supported. But it seems to me odd that it wouldn't. What is the harm in letting the derived function use inferred return type? I don't know the reasoning behind the error condition, so I can say it's definitely not a bug, but I don't know why it's this way. Perhaps there's some situation that I'm not thinking of. -Steve
Apr 14 2016