Function pointer type not recognized inside template class

房东的猫 提交于 2019-12-24 15:33:16

问题


I have this typedef to define a function pointer.

typedef Script*(*CreateObjectFn)(TiXmlElement* node);

I've created a generic container for my purpose that acts like a map. It's called Dictionary, so I've created a Dictionary of CreateObjectFn inside a class like this:

class ScriptBank
{ 
public:


~ScriptBank();
    static Dictionary<CreateObjectFn>& getInstance()
    {   
       static Dictionary<CreateObjectFn>& registry = m_registry;
       return registry;
    }

private:
    static Dictionary<CreateObjectFn> m_registry;
    ScriptBank();
};

I have various type of Script so in this Dictionary I want to put inside a certain function of the derived Script.

Now from the template class:

template <class T>
class Register
{
public:
    Register()
    {
        ScriptBank::getInstance().insert("Some string", T::create);
    }
    ~Register()
    {
    }
};

Inside the derived Script i have something like:

    static Script* create(TiXmlElement* node);
static Register<DoorChStateScript> m_Registry;

My purpose is to insert the function pointer at compilation time, but compiler seems to not recognize the right type. In the Register class I got this error: cannot convert parameter 2 from 'Script *(TiXmlElement *)' to 'CreateObjectFn *'

Any ideas?

来源:https://stackoverflow.com/questions/17828489/function-pointer-type-not-recognized-inside-template-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!