Which header file to use

Can someone tell me which header file i need to use with this code. i am getting an error when i compile it. Thanks. My include consist of #include <iostream> and #include <math.h> in my header files. I am using Visual C++ 2008 Express edition.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  using namespace std;

class RtTriangle {
private:
    const double static PI  = 3.141592653589793238462;
    
    double accuteAngle;
    double accuteAngle2;
    
    int isInputAngleValid() {
        return accuteAngle > 0.0 && accuteAngle < 90.0;
    }
    
    void setAngle2() {
        accuteAngle2 = 90.0 - accuteAngle;
    }
    
    double setRad(double degreeAngle) {
        return degreeAngle * PI / 180.0;
    }
    
    void reportTrigFunc(double degreeAngle, double radAngle) {
        printf("Angle(degrees): %6.2lf; Angle(radians): %6.3lf; Cosine: %6.3lf; Sine: %6.3lf; Tangent: %6.3lf \n",
               degreeAngle, radAngle, cos(radAngle), sin(radAngle), tan(radAngle));
    }
    
public:
    double getAngle() {
        accuteAngle = 0.0;

        cout << "Please enter an acute angle: ";
        while (! isInputAngleValid()) {
            cin >> accuteAngle;
            if (! isInputAngleValid()) {
                cout << "Nope; need an acute angle > 0.0 and < 90.0 degrees: ";
            }
        }
        
        setAngle2();
        
        return accuteAngle;
    }
    
    void reportTrigFunc() {
        double radAngle  = setRad(accuteAngle);
        reportTrigFunc(accuteAngle, radAngle);
        
        double radAngle2 = setRad(accuteAngle2);
        reportTrigFunc(accuteAngle2, radAngle2);
    }
};

int main() {
    RtTriangle* testRtTriangle;

    testRtTriangle = new RtTriangle();
    testRtTriangle->getAngle();
    testRtTriangle->reportTrigFunc();
    delete testRtTriangle;
    
    return 0;
}


Error I get:
error C2864: 'RtTriangle::PI' : only static const integral data members can be initialized within a class
Your error has nothing to do with header files. It says exactly what's wrong.

error C2864: 'RtTriangle::PI' : only static const integral data members can be initialized within a class

The keyword being "integral". You can't initialize the PI member inside of the class because it's a floating point number. You need to do one of the following:
1.) Make it non-const and initialize it in a constructor.

2.) Make it global.

But there's no point in doing either of those things, because math.h has the M_PI constant.

But since you mentioned headers... as a C++ programmer, you should be using <cmath> instead of <math.h>.
cmath.h also has the M_PI constant.
Last edited on
ok Thank you. I will try what you said.
is it sad that the only thing i looked at was if the pi decimals were accurate :p
Topic archived. No new replies allowed.