【发布时间】:2014-08-18 18:05:01
【问题描述】:
我的 c++ 程序有问题,而且 C++ 还不够好...请您帮我解决这个问题吗?
所以我使用 boost::odeint。我有我的 ode 和集成函数,来自库,在一个类 C 中。但是我有一个错误,“ode”必须是非静态的(错误:对非静态成员函数的引用必须是称为)。即使integrate和ode是同一个类。
如何使我的集成函数使用静态 ode?p>
提前谢谢你!
class C
{
public :
typedef boost::array< double , 3 > state_type;
C(const state_type &B);
~C();
const void ode( const state_type &x , state_type &dxdt , double t);
void write_out( const state_type &x , const double t );
void integration();
private :
const state_type x;
};
void C :: ode(const state_type &x , state_type &dxdt , double t)
{ (...) }
void C :: integration()
{
out.open( "results.txt" );
integrate_const( runge_kutta_fehlberg78< state_type >() , ode,
x , 0.0 , 10.0 , 0.01, write_out );
out.close();
}
## Main.cpp
using namespace std;
using namespace boost::numeric::odeint;
int main(int argc, const char * argv[])
{
C::state_type x = {{ 10.0 , 10.0 , 10.0 }};
C Com1 (x);
Com1.integration();
return 0;
}
【问题讨论】:
-
请勿在标识符中使用美元符号。
-
将 const 移到 ode 函数的末尾:void ode( const state_type &x , state_type &dxdt , double t) const;
-
我不知道你想在这里做什么: const void :: ode(const state_type &x , state_type &dxdt , double t ) - 这不是有效的 C++ 语法
-
const void返回规范应该做什么?除此之外,const void :: ode(...)应该是void C::ode(...)用于定义类成员函数。 -
@cppguy:你确定吗?我认为
const void可能是允许的(尽管在TMP 之外无用),并且声明在全局命名空间中声明了一个函数ode。我认为这是有效的 C++ 语法(虽然不是他想要的)
标签: c++ function templates boost static