2012-01-11 151 views
0

大家新年快乐等模板函数指针成员函数

我有模板一些函数指针的麻烦:

到目前为止的代码如下:

template<class T> 
    class EventMapper 
    { 
    private: 
     typedef std::wstring const (T::*messageHandler)(std::wstring const & myMessage);    //!< Templated function pointer 
     typedef std::tr1::unordered_map<std::wstring, messageHandler> umap;        //!< abbreviation for eventHandler map container 
     typedef umap::const_iterator eventCIt;               //!< abbreviation for event map const_iterator 
     typedef umap::iterator eventIt;                //!< abbreviation for event map iterator 

     //test func ptr 
     T const & myInstance; 
     umap myEventMap; 
     eventCIt myCurrentCommand;                  //!< current selected command 
    public: 
     EventMapper(T const & instance_in) : myInstance(instance_in){} 

     //register an event handler 
     void registerHandler(std::wstring const & cmd_in, messageHandler handler_in) 
     { 
      this->myEventMap.insert(umap::value_type(cmd_in, handler_in)); 
     } 

MSVS 2008 SP1下我得到这个错误:

Error 3 error C2146: syntax error : missing ';' before identifier 'eventCIt' o:\AX_FusRecAlg\include\Reconstruction\JobListEditor\Types.h 19 AX.Services.Reconstruction.JobListDataProviderTest 

不是很具描述性。我正在努力做甚么?任何提示将受到欢迎!谢谢。

+1

你不需要''之前UMAP :: const_iterator' typename'? – 2012-01-11 09:55:20

回答

3

要解决你的代码,使用typename

 typedef typename umap::const_iterator eventCIt;               //!< abbreviation for event map const_iterator 
     typedef typename umap::iterator eventIt; 

欲了解更多信息,看看template dependent names

+0

感谢您的回答和提示。 – FailedDev 2012-01-11 10:08:10

+0

是的,它是相当模糊的umap是依赖于T,但它是。 – CashCow 2012-01-11 10:16:51