I've read a lot of question but no one answer me for my specific case.
Actually I have
std::vector<Point2Dd> points;
std::vector<Triangle> triangles;
Point2Dd
is a class for a 2D point, it is not important to specify how it is implemented.
Triangle however is implemented like:
class Triangle{
public:
Triangle();
Triangle(Point2Dd* p1, Point2Dd* p2, Point2Dd* p3);
// Getter & setter
private:
Point2Dd* vA = nullptr;
Point2Dd* vB = nullptr;
Point2Dd* vC = nullptr;
}
that is, as three-pointers to vector of points.
Actually it work perfectly but I've think: if I add an other point into my vector and my vector change all memory address? All my triangles will be composed by invalid address.
I've read about using std::unique_ptr<Point2Dd>
but I don't think is the best way.
Have you any solution? Thanks :)
--- EDIT 1 ---
To clarify my problem I explain what problem I'm trying to solve. I'm doing an incremental Delaunay Triangulation (no problem with that). So I have to add once by once a point and update my triangulation.
So I've think to manage triangle as a three pointer to my points. Also I have a dag (Node -> Triangles with three children) and a structure that save adjacent triangles.
This is why I've thinked to use always a pointer, so I don't have to copy in three different structures the same points.
This is why I need to solve this problem to prevent memory reallocation.