Thread overview | |||||
---|---|---|---|---|---|
|
October 16, 2020 Call method of object variable | ||||
---|---|---|---|---|
| ||||
Hi,
I have got:
> struct Qaz
> {
> wstring read() {return null;}
> wstring hear() {return "rrrr";} }
>
> void main()
> {
> // ...
> static if(some_condition) alias method = Qaz.hear;
> else alias method = Qaz.read;
>
> // ...
> Qaz qaz;
>
> qaz.method(); // ???
> }
How to call alias "method" on object "qaz"?
|
October 16, 2020 Re: Call method of object variable | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrey | On Friday, 16 October 2020 at 08:12:59 UTC, Andrey wrote: > Hi, > I have got: >> struct Qaz >> { >> wstring read() {return null;} >> wstring hear() {return "rrrr";} } >> >> void main() >> { >> // ... >> static if(some_condition) alias method = Qaz.hear; >> else alias method = Qaz.read; >> >> // ... >> Qaz qaz; >> >> qaz.method(); // ??? >> } > > How to call alias "method" on object "qaz"? https://dlang.org/spec/traits.html#child The resulting code would be: __traits(child, qaz, method)(/*arguments go here*/); -- Simen |
October 16, 2020 Re: Call method of object variable | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen Kjærås | Thank you! |
Copyright © 1999-2021 by the D Language Foundation