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.