Using a function in another class

I'm trying to use a function from another class (my Question class) to basically run the game, but it's not allowing me. It just doesn't run it for some reason.

This is my source class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include "Question.h"
#include <cmath>
using namespace std;

/*

does not work
int main() {


	Question newGame();


	system("pause");
	return 0;
}
*/


this is from my Question class

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


void Question::newGame() {
	int input;


	for (int i = 0; i < 10; i++) {
		system("cls");
		cout << "Player One: " << endl;
		cout << questions[i].getQuestion() << endl;
		cout << questions[i].getAnswer1() << endl;
		cout << questions[i].getAnswer2() << endl;
		cout << questions[i].getAnswer3() << endl;
		cout << questions[i].getAnswer4() << endl;
		cout << "\n Please input the number of your answer: " << endl;
		cin >> input;
		if (input == questions[i].getCorrectAnswer()) {
			cout << "Player one points added!" << endl;
			//add points
			system("pause");
		}
		system("cls");

		cout << "Player Two: " << endl;
		cout << questions[i].getQuestion() << endl;
		cout << questions[i].getAnswer1() << endl;
		cout << questions[i].getAnswer2() << endl;
		cout << questions[i].getAnswer3() << endl;
		cout << questions[i].getAnswer4() << endl;
		cout << "\n Please input the number of your answer: " << endl;
		cin >> input;
		if (input == questions[i].getCorrectAnswer()) {
			cout << "Player two points added!" << endl;
			//add points
			system("pause");
		}
	}
}

Last edited on
You need to create an object before you can call a member function.
1
2
Question question; // assumed you have default ctor
question.newGame();
I'm an idiot. Thank you.
Topic archived. No new replies allowed.