assign a member function to a function pointer

前端 未结 3 536
小鲜肉
小鲜肉 2021-01-27 22:44

If I have two classes like this :

class A
{
    public:
        int *(*fun)( const int &t );
        A( int *( *f )( const int &t ) ) : fun( f ) {}
};
         


        
3条回答
  •  孤独总比滥情好
    2021-01-27 23:17

    So what to do

    Not much. Other than templating A on the type of objects for which it will hold a pointer to a member function taking a reference to a const int and returning a pointer to int.

    What you're trying to do is to mix a pointer to a free function with a pointer to member function. Whilst it sounds like they're both function pointers they're different enough to not be able to pass through the same type definition.

提交回复
热议问题