我需要做些什么才能使odeint集成函数在另一个类中编译
What do I need to do to make the odeint integrate function compile within another class?
几天来,我一直在尝试在类中编译ODEINT的integrate_adapive()函数。如果我把函数放在类之外,并有通用的函数名,那么程序就会根据需要编译和工作。(out只是一个文件的输出,并且是以前定义的)
void waterbodies::writeInfo(){
bulirsch_stoer_dense_out< state_type > stepper( 1E-9 , 1E-9 , 1.0 , 0.0 );
state_type x1 = { 0.0024 , 0.00001 , 0.0008,0.6,100,5,5,4,4,4,4,20000,0,10,10,100 }; // initial conditions
out.open( Name.c_str() );
out.precision(16);
double t = 0.0;
double max = 100;
double dt = 0.01;
boost::numeric::odeint::integrate_adaptive(
rhs,
x1 , t , max , dt, write_rhs);
out.close();
}
我有一个叫做rhs的函数,还有一个叫做write_rhs 的函数
void waterbodies::write_rhs( const state_type &x , const double t )
{
out << t << 't' << x[0] << 't' << x[1] << 't' << x[2] << 't' << x[3] << 't' << x[4] << 't' << x[5] << 't' << x[6] << 't' << x[7] << 't' << x[8] << 't' << x[9] << 't' << x[10] << 't' << x[11] << 't' << x[12] << 't' << x[13] << 't' << x[14] << 't' << x[15] << std::endl;
}
void waterbodies::rhs( const state_type &x , state_type &dxdt , const double t )
{}
state_type在标头中定义如下
typedef boost::array< double , 16 > state_type;
错误输出为:
..srcwaterbodies.cpp: In member function 'void waterbodies::writeInfo()':
..srcwaterbodies.cpp:84:32: error: no matching function for call to 'integrate_adaptive(<unresolved overloaded function type>, waterbodies::state_type&, double&, double&, double&, <unresolved overloaded function type>)'
x1 , t , max , dt, write_rhs);
^
..srcwaterbodies.cpp:84:32: note: candidates are:
In file included from C:softwareboost_1_59_0/boost/numeric/odeint/integrate/integrate.hpp:26:0,
from C:softwareboost_1_59_0/boost/numeric/odeint.hpp:67,
from ..srcwaterbodies.cpp:4:
C:softwareboost_1_59_0/boost/numeric/odeint/integrate/integrate_adaptive.hpp:36:8: note: template<class Stepper, class System, class State, class Time, class Observer> size_t boost::numeric::odeint::integrate_adaptive(Stepper, System, State&, Time, Time, Time, Observer)
size_t integrate_adaptive(
^
C:softwareboost_1_59_0/boost/numeric/odeint/integrate/integrate_adaptive.hpp:36:8: note: template argument deduction/substitution failed:
..srcwaterbodies.cpp:84:32: note: could not resolve address from overloaded function '((waterbodies*)this)->waterbodies::write_rhs'
x1 , t , max , dt, write_rhs);
^
In file included from C:softwareboost_1_59_0/boost/numeric/odeint/integrate/integrate.hpp:26:0,
from C:softwareboost_1_59_0/boost/numeric/odeint.hpp:67,
from ..srcwaterbodies.cpp:4:
C:softwareboost_1_59_0/boost/numeric/odeint/integrate/integrate_adaptive.hpp:60:8: note: template<class Stepper, class System, class State, class Time, class Observer> size_t boost::numeric::odeint::integrate_adaptive(Stepper, System, const State&, Time, Time, Time, Observer)
size_t integrate_adaptive(
^
C:softwareboost_1_59_0/boost/numeric/odeint/integrate/integrate_adaptive.hpp:60:8: note: template argument deduction/substitution failed:
..srcwaterbodies.cpp:84:32: note: could not resolve address from overloaded function '((waterbodies*)this)->waterbodies::write_rhs'
x1 , t , max , dt, write_rhs);
^
In file included from C:softwareboost_1_59_0/boost/numeric/odeint/integrate/integrate.hpp:26:0,
from C:softwareboost_1_59_0/boost/numeric/odeint.hpp:67,
from ..srcwaterbodies.cpp:4:
C:softwareboost_1_59_0/boost/numeric/odeint/integrate/integrate_adaptive.hpp:79:8: note: template<class Stepper, class System, class State, class Time> size_t boost::numeric::odeint::integrate_adaptive(Stepper, System, State&, Time, Time, Time)
size_t integrate_adaptive(
^
C:softwareboost_1_59_0/boost/numeric/odeint/integrate/integrate_adaptive.hpp:79:8: note: template argument deduction/substitution failed:
..srcwaterbodies.cpp:84:32: note: could not resolve address from overloaded function '((waterbodies*)this)->waterbodies::write_rhs'
x1 , t , max , dt, write_rhs);
^
In file included from C:softwareboost_1_59_0/boost/numeric/odeint/integrate/integrate.hpp:26:0,
from C:softwareboost_1_59_0/boost/numeric/odeint.hpp:67,
from ..srcwaterbodies.cpp:4:
C:softwareboost_1_59_0/boost/numeric/odeint/integrate/integrate_adaptive.hpp:91:8: note: template<class Stepper, class System, class State, class Time> size_t boost::numeric::odeint::integrate_adaptive(Stepper, System, const State&, Time, Time, Time)
size_t integrate_adaptive(
^
C:softwareboost_1_59_0/boost/numeric/odeint/integrate/integrate_adaptive.hpp:91:8: note: template argument deduction/substitution failed:
..srcwaterbodies.cpp:84:32: note: could not resolve address from overloaded function '((waterbodies*)this)->waterbodies::write_rhs'
x1 , t , max , dt, write_rhs);
如果你需要我解释什么,请告诉我,我会尽量让我说的更清楚。
感谢
Simon
这个问题已经回答了好几次:
在类中使用boost::numeric::odeint
您需要将rhs
和write_rhs
绑定到当前类:
// not tested
// the code also requires a C++14 compiler
auto rhs_wrapper = [this]( auto const& x , auto& dxdt , auto t ) {
this->rhs( x , dxdt , t ); };
auto obs = [this]( auto const& x , auto t ) {
this->write_rhs( x , t );
integrate_adaptive( stepper , rhs_wrapper , x , max , dt , obs );
相关文章:
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- C++-试图将函数指针推回到另一个CPP文件中的矢量时出错
- 输入到文件并输出到另一个文件,并将流文件传递给函数
- 修改函数中的指针(将另一个指针作为参数传递)
- 如何将指针从一个void函数传递到另一个C++
- 如何从另一个文件继承私有成员变量和公共函数
- 使用.find函数在c++中查找字符和另一个字符之间的大小
- C++-我可以创建另一个类的成员并在构造函数中使用它吗
- 如何在C++中将函数发送到另一个进程
- 如何在qt中从另一个类调用函数
- 如何将一个类的函数作为另一个类的另一个函数的参数传递
- 在作为静态成员包含在另一个类中的类的构造函数中使用 cout
- 将 N-arg 函数包装到另一个函数中
- 为什么我的模板化函数需要从一个迭代器转换到另一个迭代器?
- C++重载函数,一个采用基类的参数,另一个采用派生类的参数
- C++从另一个函数退出函数
- 为什么我不能在主函数之外定义一个类的对象(它继承了另一个类)?
- 在一个类中使用另一个类中的函数,而不在 c++ 中使用继承
- C++ STD 函数运算符:有没有一种方法可以通过函数将一个向量映射到另一个向量上?