Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
February 01, 2014 Implicit conversion from a base/array type | ||||
---|---|---|---|---|
| ||||
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? } |
February 01, 2014 Re: Implicit conversion from a base/array type | ||||
---|---|---|---|---|
| ||||
Posted in reply to alexhairyman | I tried something similar to (check first answer): http://stackoverflow.com/questions/121162/what-does-the-explicit-keyword-in-c-mean but I can't get it to work. But then again... I'm just starting with D. It seems not to be supported: http://forum.dlang.org/thread/teddgvbtmrxumffrhojh@forum.dlang.org#post-qxqdksfoamarwjtpjcfq:40forum.dlang.org |
February 01, 2014 Re: Implicit conversion from a base/array type | ||||
---|---|---|---|---|
| ||||
Posted in reply to alexhairyman | On Saturday, 1 February 2014 at 20:26:27 UTC, alexhairyman wrote: > 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? > } D currencly has no implicit casting operator overloading. It has been proposed before in http://wiki.dlang.org/DIP52 but i am not sure what the state of that is as of now. |
February 01, 2014 Re: Implicit conversion from a base/array type | ||||
---|---|---|---|---|
| ||||
Posted in reply to Martijn Pot | On Sat, 01 Feb 2014 21:18:12 +0000, Martijn Pot wrote: > I tried something similar to (check first answer): http://stackoverflow.com/questions/121162/what-does-the-explicit- keyword-in-c-mean > > but I can't get it to work. But then again... I'm just starting with D. > > It seems not to be supported: http://forum.dlang.org/thread/teddgvbtmrxumffrhojh@forum.dlang.org#post- qxqdksfoamarwjtpjcfq:40forum.dlang.org Thanks, a little bit more work, but thanks for the link |
February 01, 2014 Re: Implicit conversion from a base/array type | ||||
---|---|---|---|---|
| ||||
Posted in reply to TheFlyingFiddle | On Sat, 01 Feb 2014 21:23:07 +0000, TheFlyingFiddle wrote:
> On Saturday, 1 February 2014 at 20:26:27 UTC, alexhairyman wrote:
>> 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?
>> }
>
>
> D currencly has no implicit casting operator overloading. It has been proposed before in http://wiki.dlang.org/DIP52 but i am not sure what the state of that is as of now.
Hmmm, interesting
|
Copyright © 1999-2021 by the D Language Foundation