I recently debugged a strange C++ problem, in which a newly declared vector somehow had a size of 477218589. Here’s the context:
struct Triangle {
Point3 a,b,c;
Triangle(Point3 x, Point3 y, Point3 z) : a(x), b(y), c(z) {}
Vector3 flat_normal() { return (a-c)^(b-c); }
};
vector<Triangle> triangles;
Calling triangles.size() returns the value 477218589.
I ‘fixed’ the problem by changing struct Triangle to class Triangle, but I’m wondering why there’s any difference. Should I have done that typedef struct Foo { ... } Foo; magic? If so, why would that help?
If it matters, I’m using g++-4.1.
This
prints
0for me. If it also does for you, then the problem is in parts of the code not included in this snippet. If it prints anything else, something is fishy with your compiler/std lib/setup.