hi, I implemented a template base class for observer pattern,
template<class T>
class ActionListener
{
public:
ActionListener(void);
virtual ~ActionListener(void);
void registerListener(T* listener);
void unregisterListener(T* listener);
template<typename Signal>
void emit(Signal signal);
template<typename Signal, typename Parameter>
void emit(Signal signal, const Parameter& parameter);
template<typename Signal, typename Parameter1, typename Parameter2>
void emit(Signal signal,
const Parameter1& parameter1,
const Parameter2& parameter2);
private:
std::vector<T*> mListenerList;
};
class IEventListener
{
public:
virtual void messageArrived( Message* message);
virtual void messageArrived(ClientHandle* handle, Message* message);
};
i am using classes like this
emit(&IEventListener::messageArrived, message);
emit(&IEventListener::messageArrived, mHandle, message);
the problem here is, compiler cannot deduce template parameters and i couldn't gave template parameters explicitly?
Do someone have an idea ??
EDIT: Problem here is overridden function calling with template parameters."Emit" function works correctly for other function types.
Usage of this pattern is
class SampleClass : public ActionListener<IEventListener>
{
//some stuff here
//this class is observing events of IEventListener
}
by the way this is C++.