I have the following setup:
A templated class SpecialModel:
template<typename A, typename B>
class SpecialModel<A, B> {
};
A templated Worker, working on some kind of Model:
template<typename M>
class Worker<M> {
Worker(M& model);
void work();
};
And a specialization of Worker for SpecialModel:
template<typename A, typename B>
class Worker<SpecialModel<A, B> > {
Worker(SpecialModel& model);
void work();
};
Finally, there is a class that handels a given worker through a static method, basically this Manager class does lots of administration things to allow Worker focus on the real work:
template<typename W>
class Manager<W> {
Manager() {};
static void getThingsDone(W worker) {
...;
worker.work();
...;
};
};
To 'getThingsDone' for a SpecialModel, I need the following in the code:
SpecialModel<A1, B1> spmo;
Worker< SpecialModel<A1, B1> > w(spmo);
Manager<Worker< SpecialModel<A1, B1> > >::getThingsDone(w);
The last line is the one I have problems with. Isn't there a way to just say:
Manager::getThingsDone(w);
Can't the compiler deduce the type of W from w?
Why do i want that, anyway? I have an array of Workers, working on different kinds of SpecialModels (different As and Bs). Now i want to loop over this array, calling Manager::getThingsDone(w) on each worker. How should i be able to pass typeinformation on to Manager, when only having the array of workers? (The array of SpecialModles is known at compile time (part of this code is autogenerated and then compiled for this kind of special input), the array will be defined somewhere at the toplevel of the code, yet, the code doing the work should be as general as possible. However, i would be happy to find an answer without regard to this last point).