cannot cast

Namespace rswhite4 at googlemail.com
Thu May 3 00:47:19 PDT 2012


On Thursday, 3 May 2012 at 07:41:32 UTC, Simen Kjaeraas wrote:
> 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);
>     }
> }

Hm, simple. Thank you, as long as the bug isn't fixed, this has 
to be enough. :)


More information about the Digitalmars-d-learn mailing list