将函数作为参数传递的范围
Scope of passing function as a parameter
我的代码遇到了一些问题。
我有一堂课:
class SingleNeuron {
public:
double hh_function (double t , double u);
double nn_function (double t , double u);
double zz_function (double t , double u);
double VV_function (double t , double u);
void calculating_next_step( double t0, double dt ) {
hh=rk4 ( t0, hh, dt, hh_function );
nn=rk4 ( t0, nn, dt, nn_function );
zz=rk4 ( t0, zz, dt, zz_function );
VV=rk4 ( t0, zz, dt, VV_function );
}
};
/*the rk4 is a function of someone else:*/
double rk4 ( double t0, double u0, double dt, double f ( double t, double u ) );
我在 hh、nn、zz 、VV 中遇到了问题:
error C3867: 'SingleNeuron::hh_function': function call missing argument list;
use '&SingleNeuron::hh_function' to create a pointer to member
我试图将其更改为 &SingleNeuron::hh_function,问题是:
error C2664: 'rk4' : cannot convert parameter 4 from
'double (__thiscall SingleNeuron::* )(double,double)'
to 'double (__cdecl *)(double,double)'
1> There is no context in which this conversion is possible
不能将成员函数作为函数作为函数指针传递,因为没有实例的成员函数毫无意义。
如果您的hh_function仅取决于其参数。可以将其声明为静态成员函数。这样,您可以将其作为普通函数指针传递。
相关文章:
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 使用指向成员的指针将成员函数作为参数传递
- 如何将参数传递给正在使用模板的类
- 是否有C++编译器选项允许激进地删除所有函数调用,并将参数传递给具有空体的函数
- 修改函数中的指针(将另一个指针作为参数传递)
- 如何将部分流作为参数传递
- 我正在开发服务器,ip作为参数传递不起作用
- 将成员函数指针作为参数传递给模板方法
- 如何在C++中将迭代器作为函数参数传递
- 将附加参数传递给使用 beast::bind_front_handler 调用的函数
- 如何将一个类的函数作为另一个类的另一个函数的参数传递
- 将参数传递为"const"的奇怪效果
- 如何在 c++ 中将函数作为参数传递?
- 在 C++ 中将非指定类型作为参数传递的最佳方法?
- 使用引用与指针将数组作为参数传递
- 如何将成员函数作为回调参数传递给需要"typedef-ed"自由函数指针的函数?
- 将参数打包的参数传递到 std::queue 中,以便稍后使用不同的函数调用
- 为什么我不能将引用作为 std::async 的函数参数传递
- 为什么析构函数在对象引用作为参数传递时函数范围结束后调用
- 将函数作为参数传递的范围