On 11/10/2014 11:07 AM, Suliman wrote:
I can't understand how to use UFCS with instance of class:

void main()
{

string name = "Suliman";
userName username = new userName(name);

/// How to use UFCS here?
userName.name.sayHello();
///
}

class userName
{
     string name;

     this(string name)
     {
         this.name = name;
     }

     void sayHello(string name)
     {
         writeln(name);
     }
}

UFCS is about calling a free-standing function like a member function. The following example makes more sense to me:

void main()
{
    string name = "Suliman";
    userName username = new userName(name);

    username.sayHello();    // UFCS
}

// Does not have a sayHello() member function
class userName
{
    string name;

    this(string name)
    {
        this.name = name;
    }
}

void sayHello(userName u)
{
    import std.stdio;
    writeln(u.name);
}

Ali

Reply via email to