I have the following vector:
vector<boost::shared_ptr<Entity>> entities;
In order to reset the vector I am using erase
entities.erase(entities.begin(), entities.end());
Question
is this procedure correct? Will it lead to memory leak? should I also delete FactClass?
Class Entity
The constructor of class Entity takes as argument a vector of shared pointers of type FactClass
class Entity
{
public:
Entity(std::vector<boost::shared_ptr<FactClass>>);
vector<boost::shared_ptr<FactClass>> getClassFact() const;
private:
vector<boost::shared_ptr<FactClass>> _listFacts;
};
Class FactClass
The constructor of class FactClass takes as argument a vector of shared pointers of type Fact etc.
class FactClass
{
public:
FactClass(std::vector<boost::shared_ptr<Fact>>);
std::vector<boost::shared_ptr<Fact>> getFacts() const;
private:
vector<boost::shared_ptr<Fact>> _fact;
};
erase. what is the difference if I use clear? - Hani Gocclearis correct too (and more explicit about intention). - Jarod42shared_ptrwould serve? Why would you bother to use it if it didn't do that for you? - Jonathan Wakely