指向成员函数的模板函数指针
Templated function pointer to member function
大家好,新年快乐等。
我在模板化某些函数指针时遇到问题:
到目前为止的代码如下:
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_FusRecAlgincludeReconstructionJobListEditorTypes.h 19 AX.Services.Reconstruction.JobListDataProviderTest
不太具有描述性。我想做的事情有可能吗?欢迎任何提示!谢谢
要修复代码,请使用typename
:
typedef typename umap::const_iterator eventCIt; //!< abbreviation for event map const_iterator
typedef typename umap::iterator eventIt;
有关更多信息,请查看依赖于模板的名称
相关文章:
- QMetaObject invokeMethod的基于函数指针的语法
- C++-试图将函数指针推回到另一个CPP文件中的矢量时出错
- c++r值引用应用于函数指针
- 模板函数指针和lambda
- 是否可以将llvm::FunctionType转换为C/C++原始函数指针
- 带有类的函数指针
- () 函子后面的括号,而不是函数指针?
- 全局作用域中函数指针的赋值
- 使用"Task"函数指针队列定义作业管理器
- 将成员函数指针作为参数传递给模板方法
- 如何创建对象函数指针C++映射?
- 匹配函数指针作为模板参数?
- 通过函数指针定义类范围之外的方法
- 存储在类中的函数指针
- C++从函数指针数组调用函数
- 将返回值存储在函数指针数组的指针中是如何工作的?
- 整数键映射到头文件中的成员函数指针
- 从类成员函数到类 C 函数指针的转换
- 如何将内联匿名函数分配给C++函数指针
- 将字符缓冲区强制转换为函数指针