C++, function pointer to the template function pointer

前端 未结 4 1670
醉话见心
醉话见心 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:25

    template is a template :) it's not a concrete type and cannot be used as a member. e.g. you cannot define following class:

    class A
    {
        template  std::vector member;
    }
    

    because template std::vector member; is something that potentially can be specialized to many different types. you can do something like this:

    template 
    struct A
    {
     static T (*pfunction)();
    };
    
    struct B
    {
     template 
     static T getT();
    };
    
    int (*A::pfunction)() = &B::getT;
    

    here A is a specialized template and so has specialized member

提交回复
热议问题