function not declared in this scope

So, I'm making game frameworks for my own amusement, and I've hit a snag that I can't figure out. There are three functions that as far as I can tell are perfectly formatted, and which I am correctly calling upon. And yet the compiler is telling me they don't exist. The exact error is "function not declared in this scope" for two of the three. The other one is "no 'void Mc::changeXP(double)' member function declared in class Mc."

Specifically, the problem functions are:
-setStartStats(lots of stuff here);
-changeXP(double value);
-checkDeath();

edit: here are the precise error codes.
8 40 C:\Users\forre\Desktop\Coding\Projects\Misc\Relearning\Main Character.cpp [Error] 'setStartStats' was not declared in this scope

21 31 C:\Users\forre\Desktop\Coding\Projects\Misc\Relearning\Main Character.cpp [Error] no 'void Mc::changeXP(double)' member function declared in class 'Mc'

66 13 C:\Users\forre\Desktop\Coding\Projects\Misc\Relearning\Main Character.cpp [Error] 'checkDeath' was not declared in this scope

69 124 C:\Users\forre\Desktop\Coding\Projects\Misc\Relearning\Main Character.cpp [Error] no 'void Mc::setStartStats(double, double, double, double, double, double, double, double)' member function declared in class 'Mc'

the dubExponents function is a math thing from the "Run Power Of" file that I haven't fully implemented, but I've already confirmed it wasn't related by removing it, and the include it was coming from.
here's my h file:
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
#include <iostream>
#include "Run Power Of.cpp"

using namespace std;

class Mc
{	
	public:
	Mc();
	Mc(double debuggingLevel);

	//XP is current XP. levelXP is the XP needed for next level. (total XP, not relative to current XP)
	double XP;
	double levelXP;
	double level;
	//cur = current, max = max
	double curHP;
	double maxHP;
	double curMP;
	double maxMP;
	//raw stats
	double strength;
	double agility;
	double endurance;
	double intelligence;
	double wisdom;
	double charisma;
	//with stat mods
	double curStrength;
	double curAgility;
	double curEndurance;
	double curIntelligence;
	double curWisdom;
	double curCharisma;
	

	void checkLevelUp();
	void changeXP(double value);
	void levelUp();
	void modStat(int statChoice, double value);
	void damage(double value);
	//HM means health and mana. the number chooses whether to do only HP, only MP, or both
	void resetHM(double choice);
	//allows for easy adjustment of starting stats; especially if you want multiple possible stat distributions	
	void setStartStats(double str, double agi, double end, double intel, double wis, double cha, double setHP, double setMP);
	void checkDeath();
};


and here's my cpp file
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
  #include "Main Character.h"

Mc::Mc()
{
	level = 1;
	XP = 0;
	levelXP = dubExponents(2, level);
	setStartStats(1, 1, 1, 1, 1, 1, 10, 10);
	
}


void Mc::checkLevelUp()
{
	if(XP >= levelXP)
	{
		levelUp();
	}
}

void Mc::changeXP(double value)
{
	XP += value;
}

void Mc::levelUp()
{
	level += 1;
	levelXP = dubExponents(2, level);
	XP = 0;
}

void Mc::modStat(int statChoice, double value)
{
	switch(statChoice)
	{
		case 1:
			curStrength += value;
			break;
		
		case 2:
			curAgility += value;
			break;
			
		case 3:
			curEndurance += value;
			break;
			
		case 4:
			curIntelligence += value;
			break;
			
		case 5:
			curWisdom += value;
			break;
			
		case 6:
			curCharisma += value;
			break;
	}
}

void Mc::damage(double value)
{
	curHP += value;
	checkDeath();
}

void Mc::setStartStats(double str, double agi, double end, double intel, double wis, double cha, double setHP, double setMP)
{	
	strength = str;
	agility = agi;
	endurance = end;
	intelligence = intel;
	wisdom = wis;
	charisma =cha;
	maxHP = setHP;
	curHP = setHP;
	maxMP = setMP;
	curMP = setMP;
}
Last edited on
Post a link to the full code (or PM me a link) and I'll have a look at it.
You shouldn't be "including" your source file, you should instead add it to your project.

Since the OP failed to post the full error messages (the ones which include the filenames), my guess is that
#include "Run Power Of.cpp"
is the source of the beef.

Run Power Of.cpp has nothing to do with anything. It's the source file for dubExponents which I already eliminated as a possibility by removing both it and the include. I also switched to Run Power Of.h (made the .h file, properly tied it together with the relevant cpp file, changed the include, etc) and that didn't change anything either.

And this basically is the entire code so far. The only other file in the project besides these two and the "Run Power Of" files is int main, and I haven't really touched it outside of making it. The only thing in int main is the most basic possible hello world function to test the compiler before I dove in.
Here are the precise error codes:
8 40 C:\Users\forre\Desktop\Coding\Projects\Misc\Relearning\Main Character.cpp [Error] 'setStartStats' was not declared in this scope

21 31 C:\Users\forre\Desktop\Coding\Projects\Misc\Relearning\Main Character.cpp [Error] no 'void Mc::changeXP(double)' member function declared in class 'Mc'

66 13 C:\Users\forre\Desktop\Coding\Projects\Misc\Relearning\Main Character.cpp [Error] 'checkDeath' was not declared in this scope

69 124 C:\Users\forre\Desktop\Coding\Projects\Misc\Relearning\Main Character.cpp [Error] no 'void Mc::setStartStats(double, double, double, double, double, double, double, double)' member function declared in class 'Mc'
Last edited on
Post a complete program that demonstrates the problem.

This compiles:

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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using namespace std;

double dubExponents(int, int) { return 0; }

class Mc
{
public:
	Mc();
	Mc(double debuggingLevel);

	//XP is current XP. levelXP is the XP needed for next level. (total XP, not relative to current XP)
	double XP;
	double levelXP;
	double level;
	//cur = current, max = max
	double curHP;
	double maxHP;
	double curMP;
	double maxMP;
	//raw stats
	double strength;
	double agility;
	double endurance;
	double intelligence;
	double wisdom;
	double charisma;
	//with stat mods
	double curStrength;
	double curAgility;
	double curEndurance;
	double curIntelligence;
	double curWisdom;
	double curCharisma;


	void checkLevelUp();
	void changeXP(double value);
	void levelUp();
	void modStat(int statChoice, double value);
	void damage(double value);
	//HM means health and mana. the number chooses whether to do only HP, only MP, or both
	void resetHM(double choice);
	//allows for easy adjustment of starting stats; especially if you want multiple possible stat distributions
	void setStartStats(double str, double agi, double end, double intel, double wis, double cha, double setHP, double setMP);
	void checkDeath();
};

Mc::Mc()
{
	level = 1;
	XP = 0;
	levelXP = dubExponents(2, level);
	setStartStats(1, 1, 1, 1, 1, 1, 10, 10);

}


void Mc::checkLevelUp()
{
	if (XP >= levelXP)
	{
		levelUp();
	}
}

void Mc::changeXP(double value)
{
	XP += value;
}

void Mc::levelUp()
{
	level += 1;
	levelXP = dubExponents(2, level);
	XP = 0;
}

void Mc::modStat(int statChoice, double value)
{
	switch (statChoice)
	{
		case 1:
			curStrength += value;
			break;

		case 2:
			curAgility += value;
			break;

		case 3:
			curEndurance += value;
			break;

		case 4:
			curIntelligence += value;
			break;

		case 5:
			curWisdom += value;
			break;

		case 6:
			curCharisma += value;
			break;
	}
}

void Mc::checkDeath()  // ADDED
{
}

void Mc::damage(double value)
{
	curHP += value;
	checkDeath();
}

void Mc::setStartStats(double str, double agi, double end, double intel, double wis, double cha, double setHP, double setMP)
{
	strength = str;
	agility = agi;
	endurance = end;
	intelligence = intel;
	wisdom = wis;
	charisma = cha;
	maxHP = setHP;
	curHP = setHP;
	maxMP = setMP;
	curMP = setMP;
}

int main()
{
	Mc mc;
}


Then all I can think is that it's a problem with my compiler because you basically just copy-pasted my code into a different compiler and it worked perfectly.

That's what I get for using dev-cpp off an old memory stick because I was feeling nostalgic I guess XD
Last edited on
confirmed, it's my compiler. I copy pasted the code into a different header file and now it works properly. Sorry to waste everyone's time XD
No prob.
Topic archived. No new replies allowed.