Interface wierdness

Salih Dincer salihdb at hotmail.com
Sat May 7 01:23:12 UTC 2022


On Saturday, 7 May 2022 at 00:48:20 UTC, Ruby The Roobster wrote:
> Why does this happen and how to fix it?

What version compiler are you using?  I've tried it in two 
different versions (one is the newest), it works:

```d
import std;
interface I
{
     I foo();
}
class M : I
{
     this(int i)
     {
         this.i = i;
     }
     M foo()
     {
         return new M(42);
     }
     int i;
}
void main()
{
     M m = new M(3);
     m.i.writeln("(m.i)");
     M c = m.foo();
     c.i.writeln("(c.i)");
}/*Printouts:
3(m.i)
42(c.i)

Process finished.
*/
```




More information about the Digitalmars-d-learn mailing list