www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - interface assignement implies implicit const cast

Assigning a const instance to an interface implies an implicit cast. Is it
acceptable for the const-correctness ??

interface I { void foo(); }

class C : I { void foo() { writeln("a"); } }
...
C c = new C;
I i = c;     // ok
c.foo();    // ok
i.foo();    // ok
	
const C cc = c;
I ci = cc;	// no error , why ???
// cc.foo();  // compile time error - ok
ci.foo();   // const correctness overridden ???

Thanks
Oct 12 2009