S
Severin Ecker
hi!
normally i would simply do the following:
std::vector<Element> vec;
void somefunc() {
Element e;
vec.push_back(e);
}
now Element e is in the vector. thats fine as long as no polymorphic
behaviour is needed.
std::vector<Element &> vec;
void somefunc() {
Derived_from_Element e;
vec.push_back(e); //bad idea,.. e is gone after functionscope is left
}
what i want to avoid (if possible) are 2 things:
dynamic allocation of the objects, and having an extracontiner for every
type derived from the basetype to store the elements.
i hope, i made clear what i'm trying to do... so is there a solution (except
for the 2 mentioned above?)
thx, regards,
sev
normally i would simply do the following:
std::vector<Element> vec;
void somefunc() {
Element e;
vec.push_back(e);
}
now Element e is in the vector. thats fine as long as no polymorphic
behaviour is needed.
std::vector<Element &> vec;
void somefunc() {
Derived_from_Element e;
vec.push_back(e); //bad idea,.. e is gone after functionscope is left
}
what i want to avoid (if possible) are 2 things:
dynamic allocation of the objects, and having an extracontiner for every
type derived from the basetype to store the elements.
i hope, i made clear what i'm trying to do... so is there a solution (except
for the 2 mentioned above?)
thx, regards,
sev