I am trying to create list of existing objects in vector. Here is what I have so far:
void Program::addClient(string name){
vector<Client> *ptr = &(impl->clients);
Client cl(name);
ptr->push_back(cl);
}
The problem is that destructor is going to be called two times: first, when method addClient ends and second time, when destructor of this methods class will be called. Because of that, I get an error (obviously). So I thought of writing something like this:
void Program::addCategory(string name){
vector<Category> *ptr = &(impl->categories);
Category *c = new Category(name);
ptr->push_back(c);
}
By doing so, I believe, I would get rid of destructor problem, but there is another problem. My IDE throws an error at sign ->
between ptr
and push_back
, saying "no instance of overload function".
What I should do and maybe you have any tips?