I am working on a template Subject class
I will use as a base class for some event-driven programming. Currently, I am working on callback registration and I received "Template argument for template type parameter must be a type; did you forget 'typename'?
" at the line of std::map
.
I feel that the answer is related with this link, but I could not form it to solve my problem.
Here's the header of Subject
class:
#ifndef Subject_hpp
#define Subject_hpp
#include "Observer.hpp"
#include <list>
#include <map>
template<class T>
class Subject
{
public:
Subject();
virtual ~Subject();
virtual void attach( Observer* const object, void(Observer::* const func)(T) );
virtual void detach(const int pObserverId);
virtual void notify(T& pEvent);
// Clear the subject: Clear the attached observer list
void clear();
private:
std::list< std::function<void(T)> > mObserverList;
// For a better callback management in case they will
// be required to remove before the application is terminated
std::map<int, std::list< std::function<void(T)> >::iterator> mObserverRegister; // Throws: Template argument for template type parameter must be a type; did you forget 'typename'?
};
#endif /* Subject_hpp */
T
in here will be a user-defined event class such as MouseEvent
, KeyboardEvent
, etc.