member function "Quest::PlayQuest" may not be redeclared outside its class

Thanks for any guidance, Terribly sorry in advance if things look messy or bulky.

I'm trying to invoke a function declared in a separate header file/ defined in corresponding .cpp file to run within my int main(){} before it goes to system("pause"). I want to have some continutity from one quest to the next, based on user input, and I was trying to organize the functions for each next in header files to include them. However I'm getting an error on where it says

 
void Quest:PlayQuest;


Code Description
Error E0392 member function "Quest::PlayQuest" may not be redeclared
outside its class

I've not had much luck wrapping my brain around this one for my particuar case. Any guidance would help at this point.


UserInput.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
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
  #include<iostream>
#include<string>
#include<limits>
#include<Windows.h>
#include"Quests.h"
#include"QuestA.h"
	
using namespace std;

string Class[6]
{ 
	"Warrior", 
	"Wizard", 
	"Rogue", 
	"Priest", 
	"Paladin", 
	"Mage" 
};


bool IsClass = false;


void Quest::PlayQuest();

int main()
{
	string CharacterName;
	int age;


	cout << "What is your name?" << endl;
	getline(cin, CharacterName);

	system("CLS");

	cout << endl;
	cout << "Greetings to you,  " << CharacterName << ".  And what, pray, may be your age?" << endl;

	cin >> age;

	system("CLS");

	cout << endl;
	cout << "Ahh..." << age << "... A fine age to be certain, " << CharacterName << ". And do tell, what is your class?" << endl;
	cout << "You may Choose from the following by typing the number" << endl;

	cout << endl;

	for (int i = 0; i < (sizeof(Class) / sizeof(*Class)); i++) // Note: (sizeof(Class) / sizeof(*Class)) determines the correct size of the array (in case you want to change the array later)
	{
		cout << i + 1 << ") " << Class[i] << endl;
		switch (i)
		{
		case 0:
			IsWarrior = true;
			break;
		case 1:
			IsWizard = true;
			break;
		case 2:
			IsRogue = true;
			break;
		case 3:
			IsPriest = true;
			break;
		case 4:
			IsPaladin = true;
			break;
		case 5:
			IsMage = true;
			break;
		default:
			cout << endl;
			cout << "Thatis NOT acceptable!  Try again!" << endl;
			break;
		}
	}
	int i;
	cin >> i;


	system("CLS");
	
	cout << endl;
	cout << "All hail " << CharacterName << ", age: " << age << ", the brave and migty " << Class[i - 1] << endl; // Note: -1 due to the previous + 1 
	cout << endl;
	bool IsClass = true;
	
	const string Charactername = CharacterName;

	Sleep(2000);

	system("CLS");
	cout << "Congratulations, you've Completed the Introduction" << endl;

	Sleep(2000);

	system("CLS");



	

system("pause");
}


Quests.h
1
2
3
4
5
6
7
8
9
10
11

#pragma once
using namespace std;

class Quest
{
public:
	void PlayQuest();
};



Quests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
#include<iostream>
#include<string>
#include<limits>
#include<Windows.h>
#include"Quests.h"
#include"QuestA.h"
using namespace std;

void Quest::PlayQuest()
{
	cout << "let us begin the quest!\n";
}



QuestA.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#pragma once
#include<iostream>
#include"Quests.h"
using namespace std;

class QuestA : public Quest
{
public:
	
	virtual void PlayQuest() override;
	void QuestAFunction();

};


QuestA.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
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
#include<iostream>
#include<string>
#include<limits>
#include<Windows.h>
#include"QuestA.h"
using namespace std;


void QuestAFunction()
{
	void QuestA1Function();
	void QuestA2Function();
	void QuestA3Function();
	void QuestA4Function();
	string QuestA[4] //Quest A: you set off on your adventure
	{
	"Take the road North into the mountain",
	"Take the road South into the valley",
	"Take the road East into the woods",
	"Take the road West into the city"
	};
	
	system("CLS");
	cout << endl;
	cout << endl;
	cout << endl;
	cout << endl;
	cout << "As you make your way out of that heap of a town in which you sojurned, You couldn't precisely figure out which way to go.  \n";
	cout << "You stood in the town square, trying to deduce your direction... which way should this wanderer go?\n";

	for (int a = 0; a < (sizeof(QuestA) / sizeof(*QuestA)); a++) // Note: (sizeof(Class) / sizeof(*Class)) determines the correct size of the array (in case you want to change the array later)
	{
		cout << a + 1 << ") " << QuestA[a] << endl;
	}
	int a;
	cin >> a;

	switch (a) {
	case 1:
	{
		system("CLS");
		QuestA1Function();
		break;
	}
	case 2:
	{
		system("CLS");
		QuestA2Function();
		break;
	}
	case 3:
	{
		system("CLS");
		QuestA3Function();
		break;
	}
	case 4:
	{
		system("CLS");
		QuestA4Function();
		break;
	}
	}   // Which road will you take???
}
void QuestA1Function()//you took the road North into the mountain",
{
	system("CLS");
	cout << endl;
	cout << endl;
	cout << endl;
	cout << endl;
	cout << "	You took the road North into the mountain!  The air was cold and bitter, but";
	cout << "you are not a weakling! you didn't sign on for this quest just to complain about";
	cout << "fozen balls.";
}
void QuestA2Function()//you took the road South into the valley",
{
	cout << "you took the road South into the valley";
	cout << endl;
}
void QuestA3Function()//you took the road East into the woods", 
{
	cout << "you took the road East into the woods";
	cout << endl;
}
void QuestA4Function()//you took the road West into the city"
{
	cout << "you took the road West into the city";
	cout << endl;
}
Last edited on
Hello topman20000,

The comments in the code should explain everything.

"main.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
bool IsClass = false;

//void Quest::PlayQuest(); // <--- Does not need to be here. Taken care of in header files.

int main()
{
	string CharacterName;
	int age;


	cout << "What is your name?" << endl;
	getline(cin, CharacterName);

	system("CLS");

	cout << endl;
	cout << "Greetings to you,  " << CharacterName << ".  And what, pray, may be your age?" << endl;

	cin >> age;

	system("CLS");

	cout << endl;
	cout << "Ahh..." << age << "... A fine age to be certain, " << CharacterName << ". And do tell, what is your class?" << endl;
	cout << "You may Choose from the following by typing the number" << endl;

	cout << endl;

	for (int i = 0; i < (sizeof(Class) / sizeof(*Class)); i++) // Note: (sizeof(Class) / sizeof(*Class)) determines the correct size of the array (in case you want to change the array later)
	{
		cout << i + 1 << ") " << Class[i] << endl;
		switch (i)
		{
		case 0:
			IsWarrior = true; // <--- Is??? variables not defined.
			break;


"QuestA.h"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include<iostream>
#include"Quests.h"

//using namespace std;
// http://www.lonecpluspluscoder.com/2012/09/22/i-dont-want-to-see-another-using-namespace-xxx-in-a-header-file-ever-again/

class QuestA : public Quest
{
public:

	//virtual void PlayQuest() override;
	void QuestAFunction();

};


"QuestA.cpp"
1
2
3
4
5
6
7
8
9
10
#include<iostream>
#include<string>
#include<limits>
#include<Windows.h>
#include"QuestA.h"

using namespace std;

void QuestA::QuestAFunction() // <--- Is this a class function or a regular function? Looks like it should be a class function.
{


Making these changes it did compile with the exception of the undefined variables in "main".

Andy
Topic archived. No new replies allowed.