I've got a curious design problem I'chiliad trying to figure out. Basically, I accept a class called ModelSelector which has a function choose(). This function is pure virtual, the idea beingness that different usages of the underlying framework might crave different methods of model option. The problem is, different usages might *likewise* be passing dissimilar types of things into the cull() office to be modeled.
I can't make ModelSelector a templated class because information technology needs to be passed through the generic framework in several places, and in that location'south no reasonable mode they could know the item instantiation. So I thought maybe if I made the choose() office itself templated, I could specialize it in the derived classes of ModelSelector. (It would only ever be called from a derived class of a different base, with a ane-to-1 correspondence betwixt the derived classes.)
However, this code:
Lawmaking:
form ModelSelector { public: virtual ~ModelSelector() {} template<typename T> virtual heave::shared_ptr<Model> chooseModel(const T &information) const = 0; }; is giving me a compile fault. I'm guessing templates and pure virtual functions don't mix well. To summarize: I take base classes A and ModelSelector. A needs to know how to pass a ModelSelector through its interface, only only B derived from A and M derived from ModelSelector know specifically what type of thing needs to exist modeled.
Any ideas on possible design improvements here?
0 Response to "Can Template Function Be Virtual"
Post a Comment