cannot cast

Simen Kjaeraas simen.kjaras at gmail.com
Thu May 3 00:41:32 PDT 2012


On Thu, 03 May 2012 00:38:35 +0200, Namespace <rswhite4 at googlemail.com>  
wrote:

> I'm not very skillful in such "template" stories. Maybe someone can help  
> me?

The main problem here is your opCast is non-const. (it's always an  
indication of
const problems when DMD says "<X> is not callable using argument types ()")

Solution:

class A {
     int val;

     alias val this;

     T opCast(T : Object)() {
         writeln("FOO");

         return to!(T)(this);
     }

     // Add this
     T opCast(T : Object)() const {
         writeln("FOO");

         return to!(T)(this);
     }
}


More information about the Digitalmars-d-learn mailing list