cast question

Dan dbdavidson at yahoo.com
Wed Oct 31 09:59:12 PDT 2012


Why do the commented out calls to goo fail?

Thanks
Dan

-------------------------------------
import std.stdio;
struct S {
}
void goo(const ref S s) {
   writeln(s);
}
struct T {
   S s;
   void foo(const ref T other) const {
     goo(s);
     // Error: function fdsaf.goo (ref const(S) s) is
     //        not callable using argument types (S)
     // goo(cast(S)s);
     // goo(cast()s);   // same error
     writeln(typeid(S), " ", typeid(s), " ",
             typeid(cast()s), " ", typeid(cast(S)s));

   }
}
void main() {
   T t;
   t.foo(t);
   const S s1;
   S s2;
   goo(s1);
   goo(s2);
   goo(cast(S) s2);
   // goo(cast(S) s1); Also fails
}



More information about the Digitalmars-d-learn mailing list