我在编译这段简短的代码时遇到问题:
更新:我有一个更简单的代码片段,现在产生相同的错误,旧的仍然可以在帖子末尾看到。
#include <vector>
#include <iostream>
#include <functional>
class Bar {
public:
void foo(double x, double y) {
std::cout << x << std::endl;
std::cout << y << std::endl;
}
void foo2(double x) {
using namespace std::placeholders;
auto function = std::bind(&Bar::foo, this, x, _1);
function(3);
}
};
int main(int argc, char **argv) {
Bar bar;
bar.foo2(3);
}
我有一台可以正常编译的计算机:
openSUSE 12.3 with gcc 4.7.2 20130108, icc 14.0.1 20131008, boost 1_49
在这台电脑上
g++ main.cpp -std=c++11
和
icc main.cpp -std=c++11
工作。
在另一台计算机上
openSUSE 13.1 with gcc 4.8.1 20130909 , icc 14.0.1 20131008, boost 1_54
g++ main.cpp -std=c++11
有效,但是
icc main.cpp -std=c++11
导致以下错误消息:
main2.cpp(17): error: no instance of overloaded function "std::_Bind<_Functor (_Bound_args...)>::operator() [with _Functor=std::_Mem_fn<double (Bar::*)(double, double)>, _Bound_args=<Bar *, double, std::_Placeholder<1>>]" matches the argument list
argument types are: (int)
object type is: std::_Bind<std::_Mem_fn<double (Bar::*)(double, double)> (Bar *, double, std::_Placeholder<1>)>
function(3);
旧代码:
#include <vector>
#include "boost/numeric/odeint/stepper/runge_kutta4.hpp"
using namespace boost::numeric::odeint;
typedef std::vector<double> state_type;
class Right_Hand_Side {
public:
void operator()(const state_type &y, state_type &y_dot, const double t)
{}
};
int main(int argc, char **argv) {
Right_Hand_Side right_hand_side;
std::vector<double> state(10);
runge_kutta4<state_type> stepper;
stepper.do_step( std::ref(right_hand_side), state, 0, 0.1);
}
错误信息:
XXX/include/boost/numeric/odeint/util/resizer.hpp(72): error: no instance of overloaded function "std::_Bind<_Functor (_Bound_args...)>::operator() [with _Functor=std::_Mem_fn<bool (boost::numeric::odeint::explicit_stepper_base<boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>, (unsigned short)4U,
state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>::*)(const std::vector<double, std::allocator<double>> &)>, _Bound_args=<std::reference_wrapper<boost::numeric::odeint::explicit_stepper_base<boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations,
boost::numeric::odeint::initially_resizer>, (unsigned short)4U, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>>, std::_Placeholder<1>>]" matches the argument list
argument types are: (const std::vector<double, std::allocator<double>>)
object type is: std::_Bind<std::_Mem_fn<bool (boost::numeric::odeint::explicit_stepper_base<boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>, (unsigned short)4U, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations,
boost::numeric::odeint::initially_resizer>::*)(const std::vector<double, std::allocator<double>> &)> (std::reference_wrapper<boost::numeric::odeint::explicit_stepper_base<boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>, (unsigned short)4U, state_type, double, state_type, double,
boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>>, std::_Placeholder<1>)>
return f( x );
^
detected during:
instantiation of "bool boost::numeric::odeint::initially_resizer::adjust_size(const State &, ResizeFunction) [with State=std::vector<double, std::allocator<double>>, ResizeFunction=std::_Bind<std::_Mem_fn<bool (boost::numeric::odeint::explicit_stepper_base<boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>, (unsigned
short)4U, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>::*)(const std::vector<double, std::allocator<double>> &)> (std::reference_wrapper<boost::numeric::odeint::explicit_stepper_base<boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra,
boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>, (unsigned short)4U, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>>, std::_Placeholder<1>)>]" at line 196 of "XXX//include/boost/numeric/odeint/stepper/base/explicit_stepper_base.hpp"
instantiation of "void boost::numeric::odeint::explicit_stepper_base<Stepper, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::do_step_v1(System, StateInOut &, boost::numeric::odeint::explicit_stepper_base<Stepper, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::time_type, boost::numeric::odeint::explicit_stepper_base<Stepper, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::time_type) [with
Stepper=boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>, Order=(unsigned short)4U, State=state_type, Value=double, Deriv=state_type, Time=double, Algebra=boost::numeric::odeint::range_algebra, Operations=boost::numeric::odeint::default_operations, Resizer=boost::numeric::odeint::initially_resizer,
System=std::reference_wrapper<Right_Hand_Side>, StateInOut=std::vector<double, std::allocator<double>>]" at line 113 of "XXX//include/boost/numeric/odeint/stepper/base/explicit_stepper_base.hpp"
instantiation of "void boost::numeric::odeint::explicit_stepper_base<Stepper, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::do_step(System, StateInOut &, boost::numeric::odeint::explicit_stepper_base<Stepper, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::time_type, boost::numeric::odeint::explicit_stepper_base<Stepper, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::time_type) [with
Stepper=boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>, Order=(unsigned short)4U, State=state_type, Value=double, Deriv=state_type, Time=double, Algebra=boost::numeric::odeint::range_algebra, Operations=boost::numeric::odeint::default_operations, Resizer=boost::numeric::odeint::initially_resizer,
System=std::reference_wrapper<Right_Hand_Side>, StateInOut=std::vector<double, std::allocator<double>>]" at line 21 of "main.cpp"
XXX//include/boost/numeric/odeint/util/resizer.hpp(72): error: no instance of overloaded function "std::_Bind<_Functor (_Bound_args...)>::operator() [with _Functor=std::_Mem_fn<bool (boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>::*)(const std::vector<double, std::allocator<double>> &)>,
_Bound_args=<std::reference_wrapper<boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>>, std::_Placeholder<1>>]" matches the argument list
argument types are: (const std::vector<double, std::allocator<double>>)
object type is: std::_Bind<std::_Mem_fn<bool (boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>::*)(const std::vector<double, std::allocator<double>> &)> (std::reference_wrapper<boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra,
boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>>, std::_Placeholder<1>)>
return f( x );
^
detected during:
instantiation of "bool boost::numeric::odeint::initially_resizer::adjust_size(const State &, ResizeFunction) [with State=std::vector<double, std::allocator<double>>, ResizeFunction=std::_Bind<std::_Mem_fn<bool (boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>::*)(const std::vector<double, std::allocator<double>>
&)> (std::reference_wrapper<boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>>, std::_Placeholder<1>)>]" at line 146 of "XXX//include/boost/numeric/odeint/stepper/explicit_generic_rk.hpp"
instantiation of "void boost::numeric::odeint::explicit_generic_rk<StageCount, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::do_step_impl(System, const StateIn &, const DerivIn &, boost::numeric::odeint::explicit_generic_rk<StageCount, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::time_type, StateOut &, boost::numeric::odeint::explicit_generic_rk<StageCount, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::time_type) [with
StageCount=4UL, Order=4UL, State=state_type, Value=double, Deriv=state_type, Time=double, Algebra=boost::numeric::odeint::range_algebra, Operations=boost::numeric::odeint::default_operations, Resizer=boost::numeric::odeint::initially_resizer, System=std::reference_wrapper<Right_Hand_Side>, StateIn=std::vector<double, std::allocator<double>>, DerivIn=state_type, StateOut=std::vector<double, std::allocator<double>>]" at line 198 of
"XXX//include/boost/numeric/odeint/stepper/base/explicit_stepper_base.hpp"
instantiation of "void boost::numeric::odeint::explicit_stepper_base<Stepper, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::do_step_v1(System, StateInOut &, boost::numeric::odeint::explicit_stepper_base<Stepper, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::time_type, boost::numeric::odeint::explicit_stepper_base<Stepper, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::time_type) [with
Stepper=boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>, Order=(unsigned short)4U, State=state_type, Value=double, Deriv=state_type, Time=double, Algebra=boost::numeric::odeint::range_algebra, Operations=boost::numeric::odeint::default_operations, Resizer=boost::numeric::odeint::initially_resizer,
System=std::reference_wrapper<Right_Hand_Side>, StateInOut=std::vector<double, std::allocator<double>>]" at line 113 of "XXX//include/boost/numeric/odeint/stepper/base/explicit_stepper_base.hpp"
instantiation of "void boost::numeric::odeint::explicit_stepper_base<Stepper, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::do_step(System, StateInOut &, boost::numeric::odeint::explicit_stepper_base<Stepper, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::time_type, boost::numeric::odeint::explicit_stepper_base<Stepper, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::time_type) [with
Stepper=boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>, Order=(unsigned short)4U, State=state_type, Value=double, Deriv=state_type, Time=double, Algebra=boost::numeric::odeint::range_algebra, Operations=boost::numeric::odeint::default_operations, Resizer=boost::numeric::odeint::initially_resizer,
System=std::reference_wrapper<Right_Hand_Side>, StateInOut=std::vector<double, std::allocator<double>>]" at line 21 of "main.cpp"
compilation aborted for main.cpp (code 2)
我觉得这不是 boost::odeint 特有的,而是在使用 std::bind、std::function 等时出现的一个奇怪的编译器问题(这是真的,请参阅帖子顶部的新代码)