cannot cast

Namespace rswhite4 at googlemail.com
Thu May 3 01:07:44 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);
>     }
> }

My tests are failed, but isn't it possible, to reduce both 
methods to one with the inout keyword?


More information about the Digitalmars-d-learn mailing list