我正在尝试传递一个类成员函数作为参数,当我使用下面的代码时,这个方法可以很好地工作
#include <stdio.h>
class CMother;
typedef int(CMother::*FuncPtr)(char* msg);
class CMother
{
protected:
void SetFunctionPtr(FuncPtr ptr)
{
//get ptr here
}
};
class CSon : public CMother
{
public:
CSon()
{
SetFunctionPtr((FuncPtr)MyFunc);
}
private:
int MyFunc(char* msg)
{
printf(msg);
return 0;
}
};
int main()
{
CSon son;
return 0;
}但是,当我尝试用模板泛化typedef部分时,我得到了一个fatal error C1001: INTERNAL COMPILER ERROR,生成此错误的完整代码是
#include <stdio.h>
template<class T>
typedef int(T::*FuncPtr)(char* msg);
class CMother
{
protected:
void SetFunctionPtr(FuncPtr ptr)
{
//get ptr here
}
};
class CSon : public CMother
{
public:
CSon()
{
SetFunctionPtr(MyFunc);
}
private:
int MyFunc(char* msg)
{
printf(msg);
return 0;
}
};
void mmm()
{
CSon son;
}有谁能帮我这个忙吗?
发布于 2013-04-13 16:48:07
在C++11之前,C++没有模板typedefs。
https://stackoverflow.com/questions/15985935
复制相似问题