In C++, I have a certain template function that, on a given condition, calls a template function in another class. The trouble is that the other class requires the full definition of the first class to be implemented, as it creates the second class and stores them and manages them in similar fashions.
The trouble is that naturally, they fall as one class, and thus have some tight interop, except that I need them to be two classes for threading reasons. A sort of, master for all threads, one child per thread, system.
Any advice on how this can be implemented?
Edit@comment: I have a problem that looks a little like this:
class Master {
public:
Child* CreateChild() {
return new Child();
}
template<typename T> T* GetSomething(int arg) {
return NULL;
}
};
class Child {
Master* master;
template<typename T> T* GetSomething(int arg) {
if (arg) return master->GetSomething<T>(arg);
else return NULL;
}
};
Those obviously aren't the actual implementations, but similar enough to demonstrate. PIMPL would only help if these were non-template functions, but since they are, then the IMPL needs to be right here.
The Master class manages all the Children (why did I pick Master and Child instead of Parent/Child or Master/Slave?), their memory, lifetimes, etc, and a few other system-wide necessities. But the Child class provides the majority of access and in some cases must fall back to the Master class.
Also, there's no way in hell that I'm going to move to dynamic bindings. The rest of my system already thoroughly abuses dynamic bindings to the absolute max, and I simply can't afford the performance of using them again in this fashion. The Child function in question is called very, very, very often.