C++, function pointer to the template function pointer

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

    One thing you can do is have a copy of the template member function in the cpp file and point to that i.e.

    template <+typename ElementType>
    int PQueueHeap::compareFunction(ElementType First,ElementType Second)
    {   
        if (First>Second) return 1; else if (First==Second) return 0; else return -1;
    }
    
    // you cannot point to above 
    

    however you can point to

    template <+typename ElementType>
    
    int compareFunction(ElementType First,ElementType Second)
    {
    
    if (First>Second) return 1; else if (First==Second) return 0; else return -1;
    } // No error and it works! 
    

提交回复
热议问题