c++ - 将函数作为参数传递时无效使用非静态成员函数
问题描述
谁能帮我修复这个错误“错误:非静态成员函数的无效使用”行 测试(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);
}
解决方案
推荐阅读
- javascript - 如何使用 Vue/Vuex 设置动态对象值?
- javascript - 当我在连接到公司网络的同时使用公司计算机上的 NodeJS 从 URL 请求数据但我可以在浏览器中打开 URL 时,ECONNREFUSED
- android - 是否可以使用 Glide 在同一个适配器上显示 GIF 和 JPG 图像?
- html - 在rails的form_tag中禁用按钮的发布
- javascript - 如何在提交时从单选按钮向我的对象中的字段添加一个
- vert.x - 使用 Vert.x 的 JAXRS 服务
- azure - Azure AD b2c 中的自定义策略 - 声明提供程序问题指南
- functional-programming - 函数式编程:读取整数流并返回这些整数列表的优雅方式
- c# - 将模式文件打包到 dll 中以防止它们被篡改
- vim - 如何在VIM中选择括号之间的所有行