Object container
Hey guys I'm wondering what container class to use in order to be able to update my objects, I don't have to deal with deletion or memory leaks.
What I'm familiar with is vectors
and i declare it like so
1 2 3 4 5 6 7 8 9
|
class container{
vector <parent> vec1;
public:
vector <parent> add(parent &p)
{
vec1.push_back(p);
}
}
|
problem is i CANNOT update my objects in the following manner, which is what I need to do? Thanks!
1 2 3 4 5
|
contact c;
parent p("blabla");
child p1 ("alabala", "trololo");
c.add(&p);
c.add (&p1);
|
Last edited on
You can use vectors.
You need to dynamically cast to a base class:
1 2 3 4 5 6 7 8
|
class container {
vector<parent*> vec1;
public:
void add(parent* p)
{
vec1.push_back(dynamic_cast<parent*> p);
}
};
|
Last edited on
Topic archived. No new replies allowed.