Variable declared in header not declared in cpp error

Hi. I've declared some variables in the header file of a class, but when I try to compile to test, it says that they aren't declared in this scope, and I have no idea what's wrong, this works elsewhere.

Header

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
#ifndef STATCLASS_H
#define STATCLASS_H
#include <stdlib.h>
#include <iostream>
#include <string>
class statClass
{
    public:
        statClass();
        void statAllocIntro();
        void statAlloc();
        void strengthAlloc();
        void wisdomAlloc();
        void magicAlloc();
        void updStr(int updBy) {statStr += updBy;};
        void updWis(int updBy) {statWis += updBy;};
        void updMag(int updBy) {statMag += updBy;};
    protected:
    private:
        int statStr = 0;
        int statWis = 0;
        int statMag = 0;
        int money = 0;
        int maxHealth;
        int curHealth;
        int allocPoints = 10;
        char choice;
        int intChoice;
        std::string name;
};

#endif // STATCLASS_H


CPP
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
#include "statClass.h"
using std::cout;
using std::endl;
using std::cin;

statClass::statClass()
{
    //ctor
}

void strengthAlloc () {
system("CLS");
cout << "STRENGTH: " << statStr << endl;
cout << "POINTS TO ALLOCATE: " << allocPoints << endl;
cout << "---------------------" << endl;
cout << "Enter amount to give or use negative to take away." << endl;
cin >> intChoice;

if (allocPoints - intChoice < 0 && statStr + intChoice < 0) {
    cout << "Invalid, too many points to add/take." << endl;

} else {
allocPoints -= intChoice;
updStr(intChoice);
}
statAlloc();
}




void statAllocIntro (){ // statistic allocation!
       cout << "Now you can allocate your statistics." << endl;
       cout << "There are three statistics, Strength, Wisdom, and Magic." << endl;
       cout << "Strength is a measure of your raw physical power." << endl;
       cout << "Wisdom is a measure of your general knowledge." << endl;
       cout << "Finally, Magic is a measure of your proficiency with magic spells." << endl;
    system("PAUSE");
}
void statAlloc() {
while ( /* enter stuff here */ ){
        system("CLS");
        cout << "STRENGTH: " << statStr << endl;
        cout << "WISDOM: " << statWis << endl;
        cout << "MAGIC: " << statMag << endl;
        cout << "POINTS TO ALLOCATE: " << allocPoints << endl;
        cout << "-----------" << endl;
        cout << "S to allocate strength, W to allocate wisdom, M to allocate magic, and F to Finish." << endl;
        switch (choice) {
        // put cases here
        }
}

}
You can't call private members. You have to set up methods that give you access to the member.

http://www.walletfox.com/course/getset.php
Last edited on
Topic archived. No new replies allowed.