0

I am using Visual studio (1.31.1) on Linux for C++ programing with g++ compiler (g++ (Ubuntu 8.2.0-7ubuntu1) 8.2.0) and have the following error when using the bessel function:

error: ‘cyl_bessel_j’ is not a member of ‘std’

Here is the code I am using which is a copy past from the page about bessel:

#include <cmath>
#include <iostream>

int main()
{
    // spot check for n == 1
    double x = 1.2345;
    std::cout << "j_1(" << x << ") = " << std::cyl_bessel_j(1, x) << '\n';
    // exact solution for j_1
    std::cout << "(sin x)/x^2 - (cos x)/x = " << std::sin(x)/(x*x) - std::cos(x)/x << '\n';
}

VS recognizes the function as it is one suggested when I edit the code. I am runing the code using ctrl+alt+N.

  • 1
    Are you using `sph_bessel` or `cyl_bessel_j`? There is no `sph_bessel_j` function. – 1201ProgramAlarm Mar 08 '19 at 22:37
  • You linked to a page about `cyl_bessel_j`, but are using `sph_bessel_j` in your code, where `sph_bessel` is the actual [function](https://en.cppreference.com/w/cpp/numeric/special_math/sph_bessel). – Phil M Mar 08 '19 at 22:38
  • Your error message does not match your code. The former says "`sph_bessel`" while the latter has "`sph_bessel_j`". Please post the error message generated by the code you posted (or post the code that generated the error message you posted -- just don't mix stuff from two different trials). – JaMiT Mar 09 '19 at 01:16
  • Are you using -std=c++17? – n. m. could be an AI Mar 09 '19 at 10:03
  • 1) sorry for the confusion between the different Bessel functions, I tsted several one and mixup my post. 2) -std=C++17, if declared in main -> error: ‘c’ was not declared in this scope if declared before main -> error: expected unqualified-id before ‘-’ token – Pierre Blanche Mar 11 '19 at 15:22
  • I am able to run compile the code in command line using `g++ -std=c++17 test.cpp` . The VSC c_cpp_properties.json contain the line `"cppStandard": "c++17",` but it does not seems to work. Any way to compile in VSC and include the flag `-std=c++17`? – Pierre Blanche Mar 11 '19 at 21:58

0 Answers0