如何在C++; 我尝试在C++中编写球面贝塞尔函数并使用 #在我的代码中包含和sph_bessel(v,x),但发生了错误,请说明这未在该范围内声明。我使用g++test.cpp编译。请帮助我 #include <cmath> #include <iostream> #include <boost/math/special_functions/bessel.hpp> using namespace std; int main() { // spot check for n == 1 double x = 1.2345; cout << "j_1(" << x << ") = " << sph_bessel(1, x) << '\n'; }
并给出以下错误:如何在C++; 我尝试在C++中编写球面贝塞尔函数并使用 #在我的代码中包含和sph_bessel(v,x),但发生了错误,请说明这未在该范围内声明。我使用g++test.cpp编译。请帮助我 #include <cmath> #include <iostream> #include <boost/math/special_functions/bessel.hpp> using namespace std; int main() { // spot check for n == 1 double x = 1.2345; cout << "j_1(" << x << ") = " << sph_bessel(1, x) << '\n'; },c++,boost,bessel-functions,C++,Boost,Bessel Functions,并给出以下错误: error: ‘sph_bessel’ was not declared in this scope cout << "j_1(" << x << ") = " << sph_bessel(1, x) << '\n'; a.cpp:9:38: note: suggested alternative: In file included from a.cpp:3:0: /usr/include/boost/mat
error: ‘sph_bessel’ was not declared in this scope
cout << "j_1(" << x << ") = " << sph_bessel(1, x) << '\n';
a.cpp:9:38: note: suggested alternative:
In file included from a.cpp:3:0:
/usr/include/boost/math/special_functions/bessel.hpp:544:79: note: ‘boost::math::sph_bessel’
ename detail::bessel_traits<T, T, policies::policy<> >::result_type sph_bessel(unsigned v, T x)
错误:未在此范围内声明“sph_bessel”
cout错误消息告诉您该怎么做:
a.cpp:9:38: note: suggested alternative:
‘boost::math::sph_bessel’
因此,代码应该是:
cout << "j_1(" << x << ") = " << boost::math::sph_bessel(1, x) << '\n';
但人们强烈反对这样做:
因此,我建议:
namespace bmath = boost::math;
然后,您可以编写:bmath::sph\u bessel(1,x)
,而不是boost::math::sph\u bessel(1,x)
,您可能没有为sph\u bessel(v,x)
指定必要的名称空间限定符。请粘贴一个简单版本的cpp文件,编译时会显示此错误。另外,请粘贴此简单版本的编译器生成的完整错误消息。简而言之,请创建一个thank you.its work.现在我想将x从double更改为complex,并且再次发生错误。您知道如何解决此问题吗?对于C++17,此函数作为标准库提供:看起来可能不使用complex:
using namespace boost::math;
namespace bmath = boost::math;