模板类型参数的模板参数必须是一个类型

Template argument for template type parameter must be a type

我正在研究 template Subject class 我将用作某些 event-driven 编程的基础 class。目前,我正在处理回调注册,我在 std::map.

行收到“Template argument for template type parameter must be a type; did you forget 'typename'?

我觉得答案与this link有关,但我无法形成它来解决我的问题。

这是 Subject 的 header 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在这里会是一个user-defined事件class比如MouseEvent,KeyboardEvent,等等

您缺少 typename。应该是:

std::map<int, typename std::list< std::function<void(T)> >::iterator>