| class intermingling |
[18 Jun 2006|06:08am] |
I'd like to do something like:
class A { B* b; };
class B { A* a; };
That doesn't appear to want to compile. (of course?)
I haven't quite been sleeping enough, but my thinking (slightly more details) is as such:
class Triangle { const Mesh *parent; Edge *e[3]; }
class Mesh { std::vector<Triangle> triangles; std::vector<Edge> edges; }
I want a triangle to have a pointer back to its parent mesh, for the purpose of maintaining uniqueness of edges (mesh keeps a list of all of the edges that have been created; when triangle wants a new edge, for instance when it's constructed with a set of points, it asks its parent for the edge--the parent then checks to see if the edge exists, if not creates it and returns it, if so just returns it). I'm not seeing an immediate way out of this need for a recursive definition.
Maybe instead of the parent mesh itself I could just pass a pointer to the std::vector<Edge> edges?
Thanks to 4zumanga for the simple answer :) (see comments)
|
|