digitalmars.D.bugs - Cast Object - get null
- Namespace (12/12) Apr 18 2012 override bool opEquals(Object o) const {
- Namespace (20/20) Apr 18 2012 I forget my test context:
- bearophile (4/7) Apr 18 2012 I suggest to ask such questions in D.learn.
- Namespace (3/10) Apr 18 2012 If you say so.
override bool opEquals(Object o) const { if (o is null) { return false; } writeln(o); // write: cast.Vector2D!(float).Vector2D Vector2D!(T) vec = cast(Vector2D!(T)) o; writeln(vec); // write: null // ... It seems the cast fail, but the question is: why?
Apr 18 2012
I forget my test context: void main() { alias Vector2D!(short) Vector2s; alias Vector2D!(float) Vector2f; Vector2f vf = Vector2f(23, 42); Vector2s vs = Vector2s(vf); writefln("vs.x: %d, vs.y: %d", vs.x, vs.y); Vector2s vs2 = Vector2s(23, 42); if (vs2 == vf) { writeln("equal"); } } Vector2D is my own class. If i compare vs2 with vs it works fine, but if i compare vs or vs2 with vf, the cast fail and i get a null-reference. How can i avoid this?
Apr 18 2012
Namespace:Vector2D is my own class. If i compare vs2 with vs it works fine, but if i compare vs or vs2 with vf, the cast fail and i get a null-reference. How can i avoid this?I suggest to ask such questions in D.learn. Bye, bearophile
Apr 18 2012
On Wednesday, 18 April 2012 at 16:34:08 UTC, bearophile wrote:Namespace:If you say so. Then close or delete this thread please.Vector2D is my own class. If i compare vs2 with vs it works fine, but if i compare vs or vs2 with vf, the cast fail and i get a null-reference. How can i avoid this?I suggest to ask such questions in D.learn. Bye, bearophile
Apr 18 2012