大家新年快乐等。
我无法使用模板化某些函数指针:
目前的代码如下:
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
不是很具描述性。我甚至想做什么?任何提示都会受到欢迎!感谢。
答案 0 :(得分:3)
要修复代码,请使用typename
:
typedef typename umap::const_iterator eventCIt; //!< abbreviation for event map const_iterator
typedef typename umap::iterator eventIt;
有关详细信息,请查看template dependent names