www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Call method of object variable

reply Andrey <saasecondbox yandex.ru> writes:
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"?
Oct 16 2020
parent reply Simen =?UTF-8?B?S2rDpnLDpXM=?= <simen.kjaras gmail.com> writes:
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
Oct 16 2020
parent Andrey <saasecondbox yandex.ru> writes:
Thank you!
Oct 16 2020