C++, function pointer to the template function pointer

前端 未结 4 1660
醉话见心
醉话见心 2020-12-05 00:24

I am having a pointer to the common static method

class MyClass
{
  private:
    static double ( *pfunction ) ( const Object *, const Object *);
    ...
};
<         


        
4条回答
  •  春和景丽
    2020-12-05 01:22

    In the second case, getA is not a function anymore but a function template, and you can't have a pointer to function template.

    What you can do is have pfunction point to a particular getA instance (ie: for T = int) :

    class MyClass
    {
        static double (*pfunction)(const Object *, const Object *);
    };
    
    double (*MyClass::pfunction)(const Object *o1, const Object *o2)  = &SomeClass::getA;
    

    But I don't think there is a way to get pfunction to point on any possible instance of getA.

提交回复
热议问题