我正在尝试将类成员函数作为参数传递
当我使用以下代码时,这完美地工作

#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;
}


谁能帮我这个忙。

最佳答案

C ++在C ++ 11之前没有模板typedef。

10-07 19:17
查看更多