I've got a curious design problem I'm trying to figure out. Basically, I have a class called ModelSelector which has a function choose(). This function is pure virtual, the idea existence that different usages of the underlying framework might require different methods of model selection. The trouble is, different usages might *also* be passing different types of things into the choose() part to be modeled.
I tin can't make ModelSelector a templated class because information technology needs to exist passed through the generic framework in several places, and there'due south no reasonable manner they could know the particular instantiation. So I idea mayhap if I made the cull() function itself templated, I could specialize it in the derived classes of ModelSelector. (It would only ever exist chosen from a derived class of a different base of operations, with a i-to-1 correspondence between the derived classes.)
Still, this lawmaking:
Lawmaking:
class ModelSelector { public: virtual ~ModelSelector() {} template<typename T> virtual boost::shared_ptr<Model> chooseModel(const T &data) const = 0; }; is giving me a compile error. I'one thousand guessing templates and pure virtual functions don't mix well. To summarize: I accept base classes A and ModelSelector. A needs to know how to laissez passer a ModelSelector through its interface, simply only B derived from A and 1000 derived from ModelSelector know specifically what type of thing needs to be modeled.
Any ideas on possible design improvements here?
0 Response to "Can A Template Class Have Virtual Functions"
Post a Comment