Type converter from build in to user type

js.mdnq js_adddot+mdng at gmail.com
Thu Nov 29 18:59:05 PST 2012


I have a struct I am trying convert from int's to the type. Since 
I can't add a opCast overload to an int I don't know how to do 
it. My opCast convertors in my class do not work for the 
assignment operator:


class myType
{
    opCast, opAssign
}

mytype = 3;

Error that we can't convert an int to myType. While it's very 
easy to go from a myType to whatever by writing a cast for it(in 
the class), how do I go from an int to myType(in the class)?

For example, I can do

mytype = mytype.opCast(3);
or mytype.opAssign(3);

but these are too verbose to be useful.




More information about the Digitalmars-d-learn mailing list