错误:Char 26: fatal error: reference to non-static member function must be called

主要原因是我使用了函数指针,而函数指针所指函数须得是静态才行

class Solution {
public:
    vector<int> exchange(vector<int>& nums) {
        return ReOrder(nums,iseven);
    }
    vector<int> ReOrder(vector<int>& nums,bool (*func)(int)) {
		......
    }
    bool iseven(int n){//这里有误,应改成static
        return (n&0x1)==0;
    }
};

添加static,完美解决:

class Solution {
public:
    vector<int> exchange(vector<int>& nums) {
        return ReOrder(nums,iseven);
    }
    vector<int> ReOrder(vector<int>& nums,bool (*func)(int)) {
		......
    }
    static bool iseven(int n){
        return (n&0x1)==0;
    }
};

posted on 2020-05-15 11:15  丁错儿  阅读(425)  评论(0编辑  收藏  举报

导航