struct, ref in, and UFCS

Puming via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jun 30 22:11:37 PDT 2014


On Tuesday, 1 July 2014 at 05:09:49 UTC, Puming wrote:
> Hi,
>
> I have a struct and want to extends its methods, like:
>
> ```d
> struct Server
> {
>   string name;
>   string ip;
>   int port;
>   string user;
> }
> ```
>
> extension method here:
>
> ```d
> string prompt(ref in Server server)
> {
>    return server.user ~ "@" ~ server.ip ~ ":" ~ server.port;
> }
>
> ```
should be `server.port.to!int`;
>
> and call it with UFSC:
>
> ```d
> string p = server.prompt;
> ```
>
> is this the correct way to use struct and UFCS? it does not 
> seem to copy there.



More information about the Digitalmars-d-learn mailing list