I'm trying to get some simple template-based design working, and stumbled onto template inter-dependence. Now I know that I can resolve this using virtual functions and (in this particular artificial case) by turning EventHandler methods into templates instead of whole class. But is there some way to have two inter-dependent templates, providing that they use only pointers to each other?
This is simplified example:
typename MySocket;
template<typename SocketClass> struct EventHandler {
void receiveCallback(SocketClass *s) {
}
};
template <typename HandlerType> class Socket {
HandlerType *handler;
};
typedef EventHandler<MySocket> MyHandler ;
typedef Socket<MyHandler> MySocket ;
MyHandler h;
MySocket socket;
int main() {
return 0;
}
For this code compiler gives an error stating that Socket is redefined. Any ideas? C++11/14 is fine for me.