On Mon, 10 Nov 2014 19:07:38 +0000, 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);
>      }
> }

This has nothing to do with new--you're trying to use a virtual function 
scoped
to class userName with a string.  Rewrite it to a static module-scoped 
function:

class userName {
        string name;

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

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

void main()
{

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

        userName.name.sayHello();
}

Reply via email to