struct, ref in, and UFCS

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 1 06:53:11 PDT 2014


On 07/01/2014 03:21 AM, Puming wrote:

 > I can safely assume ref is better than pointer here

I agree.

 > because it plays nicely with UFCS.

I don't understand that part. :) The following is the same program with 
just two differences: prompt() takes a pointer and 'server' is a pointer.

import std.conv;

struct Server
{
     string name;
     string ip;
     int port;
     string user;
}

string prompt(Server * server)
{
     return server.user ~ "@" ~ server.ip ~ ":" ~ server.port.to!string;
}

void main()
{
     auto server = new Server("bzzt", "192.168.0.1", 80, "nobody");
     string p = server.prompt;
}

Ali



More information about the Digitalmars-d-learn mailing list