Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
October 27, 2020 Is there something I'm not getting here? | ||||
---|---|---|---|---|
| ||||
Following code doesn't work(it's not the actual code but it represents it). Is there some rule about function overrides that I don't know about? class a { public override string toString() { //... } } class b : a { public override string toString() { //... } } The error I keep getting no matter what says: Error: Multiple Overrides of Same Function. Anybody know what I should do? |
October 27, 2020 Re: Is there something I'm not getting here? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ruby The Roobster | On Tuesday, 27 October 2020 at 01:19:58 UTC, Ruby The Roobster wrote:
> Following code doesn't work(it's not the actual code but it represents it). Is there some rule about function overrides that I don't know about?
>
> class a {
> public override string toString() {
> //...
> }
> }
>
> class b : a {
> public override string toString() {
> //...
> }
> }
>
> The error I keep getting no matter what says: Error: Multiple Overrides of Same Function. Anybody know what I should do?
Okay. Realized this wasn't actually affecting my program, but is there any explanation for why this doesn't work?
|
October 26, 2020 Re: Is there something I'm not getting here? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ruby The Roobster | On 10/26/20 9:19 PM, Ruby The Roobster wrote: > Following code doesn't work(it's not the actual code but it represents it). Is there some rule about function overrides that I don't know about? > ... > The error I keep getting no matter what says: Error: Multiple Overrides of Same Function. Anybody know what I should do? It works for me. The "shorten" link on run.dlang.io no longer works, but here is a working example: ``` import std; class A { public override string toString() { return "a"; } } class B : A { public override string toString() { return "b"; } } void main() { A a = new A(); B b = new B(); writeln(a); writeln(b); } ``` |
October 27, 2020 Re: Is there something I'm not getting here? | ||||
---|---|---|---|---|
| ||||
Posted in reply to James Blachly | On Tuesday, 27 October 2020 at 01:26:56 UTC, James Blachly wrote: > On 10/26/20 9:19 PM, Ruby The Roobster wrote: >> Following code doesn't work(it's not the actual code but it represents it). Is there some rule about function overrides that I don't know about? >> > ... >> The error I keep getting no matter what says: Error: Multiple Overrides of Same Function. Anybody know what I should do? > > It works for me. > ... I think he is referring to this: import std; class B{ public override string toString(){ return null; } public override string toString(){ return toString(null); } } void main() { B b = new P(); } Error: function `B.toString` multiple overrides of same function You can view: https://www.jdoodle.com/iembed/v0/3rm Matheus. |
October 27, 2020 Re: Is there something I'm not getting here? | ||||
---|---|---|---|---|
| ||||
Posted in reply to matheus | On Tuesday, 27 October 2020 at 02:21:39 UTC, matheus wrote:
> On Tuesday, 27 October 2020 at 01:26:56 UTC, James Blachly wrote:
>> On 10/26/20 9:19 PM, Ruby The Roobster wrote:
>>> Following code doesn't work(it's not the actual code but it represents it). Is there some rule about function overrides that I don't know about?
>>>
>> ...
>>> The error I keep getting no matter what says: Error: Multiple Overrides of Same Function. Anybody know what I should do?
>>
>> It works for me.
>> ...
>
> I think he is referring to this:
> ...
I mean he may be having a duplicate method in the same class.
Matheus.
|
Copyright © 1999-2021 by the D Language Foundation