Question

i'm trying to pass a class member function as a parameters this work perfectly when i'm using the folowing code

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

but when i try to generalize the typedef section with a template i'm getting a fatal error C1001: INTERNAL COMPILER ERROR the complete code that generate this error is

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

can any one help me with this please.

Was it helpful?

Solution

C++ have no template typedefs until C++11.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top