digitalmars.D - opImplictCast questions
- Steven Schveighoffer (17/17) Nov 29 2007 When opImplicitCast comes along, if I do the following:
- Regan Heath (8/33) Nov 30 2007 My gut feeling is that it will not compile, unless you change "typedef"
When opImplicitCast comes along, if I do the following: typedef int X; struct Y { X opImplicitCast() {...} } This should compile: Y y; X x = y; Should this? Y y; int i = y; (hint hint: I would like it NOT to compile) Also, I know const is out and that's great and all, but when do we get opImplicitCast? Not to be pushy or anything :) -Steve
Nov 29 2007
Steven Schveighoffer wrote:When opImplicitCast comes along, if I do the following: typedef int X; struct Y { X opImplicitCast() {...} } This should compile: Y y; X x = y; Should this? Y y; int i = y; (hint hint: I would like it NOT to compile) Also, I know const is out and that's great and all, but when do we get opImplicitCast? Not to be pushy or anything :)My gut feeling is that it will not compile, unless you change "typedef" to "alias" and then it will. I believe D's typedef creates such a unique/separate type that even though it is based on 'int' (in this case) it does not even 'inherit' the implicit conversions of 'int', let alone implicitly convert to it's base type. R
Nov 30 2007