C++ design question, container of instances and pointers
- by Tom
Hi all,
Im wondering something.
I have class Polygon, which composes a vector of Line (another class here)
class Polygon
{
std::vector<Line> lines;
public:
const_iterator begin() const;
const_iterator end() const;
}
On the other hand, I have a function, that calculates a vector of pointers to lines, and based on those lines, should return a pointer to a Polygon.
Polygon* foo(Polygon& p){
std::vector<Line> lines = bar (p.begin(),p.end());
return new Polygon(lines);
}
Here's the question:
I can always add a Polygon (vector
Is there a better way that dereferencing each element of the vector and assigning it to the existing vector container?
//for line in vector<Line*> v
//vcopy is an instance of vector<Line>
vcopy.push_back(*(v.at(i))
I think not, but I dont really like that approach.
Hopefully, I will be able to convince the author of the class to change it, but I cant base my coding right now to that fact (and i'm scared of a performance hit).
Thanks in advance.