Implicit conversion from a base/array type

alexhairyman alexhairyman at gmail.com
Sat Feb 1 12:26:25 PST 2014


Is there a way to implicitly convert *FROM* a base type? I have 
an implicit conversion to a base type (float[2]) in a struct, but 
now I'd like to be able to implicitly convert from a base type 
(in this case a float[2]) to a struct.

Is this even allowed? Is it incorrect or unsafe? I'm still pretty 
new so there could be a major reason to not want to do this. I 
also did a lot of searching of the site, I hope I didn't miss 
something major, but I might have.

example :

struct Coord {...} // X,Y wrapper-like type, implicitly converts 
to/from float

void DoCoord(Coordinate c) {... do stuff...}

void main()
{
   DoCoord ([0.0f, 5.0f]); // Is it possible to set this up?
}


More information about the Digitalmars-d-learn mailing list