Let’s say i have following class:
template <typename T>
class CModule{
public:
virtual void process( std::multiamp<int, T>) = 0;
}
and derived class:
template <typename T>
class CModuleDeriv: public CModule<T>{
public:
virtual void process( std::multiamp<int, T>){....};
}
and class where i wan’t to implement this functionality:
class Client{
std::vector<CModule<T>*> oModuleList_; // <--- this is not possible error
public:
void moduleLoader(){
oModuleList_.resize(1);
if( some_condition ){
oModuleList_[0] = CModuleDeriv<int>();
}else{
oModuleList_[0] = CModuleDeriv<double>();
}
}
}
is it possible?
is there any other solution ?
I can’t use boost :/
First of all, in the future please post code that almost compiles (or even better one that compiles!), because those “little” details you omit sometimes changes the semantics of your code. So, submitting almost compilable code has almost unambiguous semantics…
Here’s some code that might or might not solve your problem:
This, by itself is not a solution to your problem, because your not compiling code snipplet would not solve anything even if it compiled. You are pushing things with inherently different types to a common list and losing their type, so how will you know how to use the elements in the future? This is a semantic question.
I’ll have a wild guess that this is probably what you’re trying to do:
See, no more commented nags 🙂