I have a Code::Blocks project with a few files, including main.cpp
, Line_segment.cpp
and its corresponding header, Line_segment.h
. The header file, as well as the main file, #include
the <cmath>
library in their preprocessor directives. One of the objects defined in <cmath>
is the constant M_PI
, which is simply the number pi.
Using M_PI
works just fine in main()
, and I'm able to write simple things like std::cout << M_PI*2. << '\n'
and I'll get an output of 6.28... as expected. However, when I try to do the same thing in the Line_segment.cpp
file and compile, I get a compilation error saying that 'M_PI' was not declared in this scope
. The same happens if I include <cmath>
directly into the .cpp file, and if I try using "math.h"
. Another observation is that M_PI
, M_PI_2
and M_PI_4
all show up in the code suggestion popup when I type the name out, which implies that Code::Blocks is recognizing the name in the scope of that file.
Is there any known reason why this happens? Any help is greatly appreciated.