Returning a dynamic value from a function

is this considered a memory leak?

Polygon* create_square(const Vector2d& position, const RGB& colour, const std::string name)
{
// Polygon, Vector2D, RPG and Vertex2d are structs with public data members only
Polygon *temp = new Polygon;

temp->name = name;
temp->colour = colour;
temp->position = position;
temp->vertices = new Vertex2d;

return temp;
}
Last edited on
Not if you delete it when you're done with it. Although your 'Polygon' isn't being deleted by what is shown here, there is nothing stopping you from deleting it later.

Something to consider, given the variable names you have here maybe a "square" should be a child class of your 'Polygon' class.
Topic archived. No new replies allowed.