将函数作为参数传递时,非静态成员函数的使用无效

问题描述

谁能帮我修复这个错误错误:无效使用非静态成员函数”在行 test(3,a.foo); 当我编译代码

#include <iostream>
#include <string>

class A {
 public:
  int x = 0;
  void foo(int y){
   x = x + y;    
  }
};
template<typename Func>
void test(int d,Func f){
  f(d);    
}

int main()
{
  A a;
  a.foo(4);
  std::cout << a.x;
  test(3,a.foo);
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)