Am 15.05.2013 17:08, schrieb Artur Skawina: > On 05/15/13 13:04, Dicebot wrote: >> On Wednesday, 15 May 2013 at 10:31:29 UTC, David wrote: >>>> "&c" is address of reference, no class instance. I don't know if there >>>> is a way to get a pointer to class instance in D but I am not aware of one. >>> >>> A simple cast to void* should do it: cast(void*)c > > class C { auto opCast(T:void*)() { return null; } } > > So - no - a simple cast to void* won't always work, as the op can be > overloaded, even if only by accident. > > See also: > http://forum.dlang.org/thread/mutvhrrdfzunbrhmv...@forum.dlang.org#post-mailman.2432.1354406246.5162.digitalmars-d-learn:40puremagic.com > and > http://d.puremagic.com/issues/show_bug.cgi?id=8545 > > > artur >
Overloading cast is broken and shouldn't be in the language (imo). Why broken? If you only want to overload cast(bool) (for if(x) which calls if(cast(bool)x -> x.opCast!bool()) you have to overload all other possible casts, otherwise compiler will complain that this cast is no overloaded. Also overloading a cast doesn't really make any sense (except the bool case), that's also the reason why I really hate std.conv.to's new behaviour of calling opCast, this makes no sense, to! does a conversion not a cast.