class BaseClass{
public:
virtualvoid smthSmth(void) = 0;
};
template <class T> class TemplClass: public BaseClass{
public:
T value;
virtualvoid smthSmth(void) = 0;
};
//And take that as vector element type
class Container{
private:
vector<BaseClass> list;
public:
void add(BaseClass tcObject){ list.push_back(tcObject); }
void smthSmthLast(void){
list.back().smthSmth();
list.pop_back();
}
};
This works fine in case of NOTHING will be added or changed on any inheritting class!
But that is not a proper solution in the view of object oriented programming.
Because the base class has to have the sum of all methods (of all derived classes) which will be called by the container. That does not make any sense! That's not dynamic or generic at all!!!
Is that really an unsolveable problem??? Or is there smth like TmplClass<?> in Java.
(Hint: The code lines are out of my head, i didn't test it. So it could be possible that syntax errors are inside.)
Keep in mind that TempClass is not a class but a class template, it doesn't have object code generated if no classes are instancied by using the class with actual template parameters.
C++ templates are very different from JAVA generics and don't work the same way at all.
But then the template classes all use the same type!
I want them to have different types! I guess (because of your last answer, aqaz), it is just not possible?
seraph, I honestly find that container solutions are rather bad. I'd rather just let the user of my class make a container themselves which generally involves little to no effort and simplifies your original base class design.