On Mon, 10 Nov 2014 19:07:38 +0000 Suliman via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com> wrote:
> /// How to use UFCS here? > userName.name.sayHello(); > /// you can't. a little explanation: UFCS substitutes only the first argument. and for class methods first argument is hidden 'this'. so you can't do it in this way, you have to write `userName.sayHello(name);` here. on the very low level calling class methods looks like this: // what you see: myobj.method(arg); // what compiler does: // method(myobj, arg); so in your example compiler sees this: sayHello(userName.name); which is obviously not what you want, 'cause you need this: sayHello(userName, name); or, taking it the easier way: UFCS is for *functions*, not for *methods*. that's why it "uniform *function* call syntax". it's not expected to work with methods, as the name suggests. maybe it will be easier to remember this way, rather than diving into compiler code transformations. ;-)
signature.asc
Description: PGP signature