Need help ASAP: Don't know how to fix this error

okay so in my main file i get an error that says:
"no default constructor exists for class "question" where it says question Game[10)

i have an idea on what it's talking about, but i don't have the slightest clue on how to fix it.
Here is my 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
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
#ifndef	QUESTION_H
#define QUESTION_H
#include <string>
using namespace std;

class question
{
private:
	string questions, answer1, 
		answer2, answer3, answer4;
	int correctAnswer;

public:
	question(string Q, string A1, string A2, string A3, string A4, int CA)		// Constructor
	{
		questions = Q;
		answer1 = A1;
		answer2 = A2;
		answer3 = A3;
		answer4 = A4;
		correctAnswer = CA;
	}

	// "Set" and "Get" the Questions function.
	void setQuestions();
	string getQuestions() const;

	// "Set" and "Get" the Answer1 function.
	void setAnswer1();
	string getAnswer1() const;

	// "Set" and "Get" the Answer2 function.
	void setAnswer2();
	string getAnswer2() const;

	// "Set" and "Get" the Answer3 function.
	void setAnswer3();
	string getAnswer3() const;

	// "Set" and "Get" the Answer4 function.
	void setAnswer4();
	string getAnswer4() const;

	// "Set" and "Get" the Correct Answer function.
	void setCorrectAnswer();
	int getCorrectAnswer() const;

void setQuestions(string Q)
{
	questions = Q;
}

string getQuestions()
{
	return questions;
}

void setAnswer1(string A1)
{
	answer1 = A1;
}

string getAnswer1()
{
	return answer1;
}

void setAnswer2(string A2)
{
	answer2 = A2;
}

string getAnswer2()
{
	return answer2;
}

void setAnswer3(string A3)
{
	answer3 = A3;
}

string getAnswer3()
{
	return answer3;
}

void setAnswer4(string A4)
{
	answer4 = A4;
}

string getAnswer4()
{
	return answer4;
}

void setCorrectAnswer(int CA)
{
	correctAnswer = CA;
}

int getCorrectAnswer()
{
	return correctAnswer;
}

};
#endif 


and here is my main:
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include "question.h"
#include <string>
#include <iomanip>
#include <iostream>
using namespace std;

void questionAnswers(question [], int);

int main()
{
	char response, start;

	do
	{
		question Game[10];
		int count = 0;
		int player1Choice, player2Choice;					// Holds the player's answers.
		int player1Points = 0, player2Points = 0;			// Holds the player's total points.

		// Describe the game to the user.
		cout << "Welcome to:" << endl << endl;
		cout << "-------------the FANTABULOUS TRIVIA GAME!-------------" << endl << endl;
		cout << "This is the TWO PLAYER GAME where you will be challenged by TRIVIA QUESTIONS!" << endl;
		cout << "You will be asked a total of 10 questions." << endl;
		cout << "First one to get them all right with the most points WINS!" << endl << endl;

		// Ask the user if they would like to start the game.
		cout << "Ready to start?" << endl;
		cout << "Please type 'Y' or 'y' for YES." << endl;
		cout << "Alternatively type 'N' or 'n' for NO." << endl;
		cin >> start;

		// If loop to start the game.
		if(start == 'Y' || start == 'y')
		{
			// First question.
			Game[0].setQuestions("What is the capital of New Jersey?");
				Game[0].setAnswer1("1. Alaska");
				Game[0].setAnswer2("2. Toronto");
				Game[0].setAnswer3("3. applesauce");
				Game[0].setAnswer4("4. Trenton");
				Game[0].setCorrectAnswer(4);

			// Second question.
			Game[1].setQuestions("What is America's favorite past time?");
				Game[1].setAnswer1("1. War");
				Game[1].setAnswer2("2. Football");
				Game[1].setAnswer3("3. Baseball");
				Game[1].setAnswer4("4. Soccer");
				Game[1].setCorrectAnswer(3);

			// Third question.
			Game[2].setQuestions("What makes the grass green?");
				Game[2].setAnswer1("1. Green");
				Game[2].setAnswer2("2. Chlorophyll");
				Game[2].setAnswer3("3. Germs");
				Game[2].setAnswer4("4. Yellow");
				Game[2].setCorrectAnswer(2);

			// Fourth question.
			Game[3].setQuestions("What year did Germany invade Poland at the start of WW2?");
				Game[3].setAnswer1("1. 1939");
				Game[3].setAnswer2("2. 1856");
				Game[3].setAnswer3("3. 1400");
				Game[3].setAnswer4("4. 1946");
				Game[3].setCorrectAnswer(1);

			// Fifth question.
			Game[4].setQuestions("What is the eight planet of the solar system?");
				Game[4].setAnswer1("1. Mars");
				Game[4].setAnswer2("2. Jupiter");
				Game[4].setAnswer3("3. Poseidon");
				Game[4].setAnswer4("4. Neptune");
				Game[4].setCorrectAnswer(4);

			// Sixth question.
			Game[5].setQuestions("Which famous superhero was from the planet Krypton?");
				Game[5].setAnswer1("1. Batman");
				Game[5].setAnswer2("2. Deadpool");
				Game[5].setAnswer3("3. Superman");
				Game[5].setAnswer4("4. Wolverine");
				Game[5].setCorrectAnswer(3);

			// Seventh question.
			Game[6].setQuestions("What 2010 film had to do with entering people's dreams?");
				Game[6].setAnswer1("1. Shutter Island");
				Game[6].setAnswer2("2. Hugo");
				Game[6].setAnswer3("3. The Matrix");
				Game[6].setAnswer4("4. Inception");
				Game[6].setCorrectAnswer(4);

			// Eighth question.
			Game[7].setQuestions("What is 44 divided by 4");
				Game[7].setAnswer1("1. 11");
				Game[7].setAnswer2("2. 89");
				Game[7].setAnswer3("3. 6");
				Game[7].setAnswer4("4. 7");
				Game[7].setCorrectAnswer(1);

			// Ninth question.
			Game[8].setQuestions("When is Independence Day?");
				Game[8].setAnswer1("1. February 27");
				Game[8].setAnswer2("2. July 4");
				Game[8].setAnswer3("3. May 5");
				Game[8].setAnswer4("4. July 2");
				Game[8].setCorrectAnswer(2);\

			// Tenth question.
			Game[9].setQuestions("What is the Law of Conservation of Energy?");
				Game[9].setAnswer1("1. That energy can be created, but not destroyed.");
				Game[9].setAnswer2("2. That energy is simply an illsuion.");
				Game[9].setAnswer3("3. That energy cannot be created nor destroyed.");
				Game[9].setAnswer4("4. That energy cannot be created, but can be destroyed.");
				Game[9].setCorrectAnswer(2);

			// While loop for the actual game.
			while(count < 9)
			{
				cout << setw(10) << "Question #" << (count + 1) << "." << endl;
				questionAnswers(Game, count);

				cout << "Player 1 Answer: ";
				cin >> player1Choice;

				cout << "Player 2 Answer: ";
				cin >> player2Choice;

				// If Player 1 is right, they get a point.
				if(Game[count].getCorrectAnswer() == player1Choice)
				{
					player1Points++;
				}

				// If Player 2 is right, they get a point.
				if(Game[count].getCorrectAnswer() == player2Choice)
				{
					player2Points++;
				}
				count++;
			}

			// If loops to determine who wins.
			if (player1Points > player2Points)
			{
				cout << "Player 1 WINS!" << endl;
				cout << "Congratulations Player 1!!" << endl;
			}

			if (player1Points < player2Points)
			{
				cout << "Player 2 WINS!" << endl;
				cout << "Congratulations Player 2!!" << endl;
			}

			if (player1Points == player2Points)
			{
				cout << "Player 1 and Player 2 are now tied!" << endl;
				cout << "You both LOST!!" << endl;
			}

		}
		else if(start == 'n' || start == 'N')
		{
				cout << "Thanks for your participation in the FANTABULUS TRIVIA GAME!" << endl;
		}

		// Ask the user if they would like to rerun the program.
		cout << endl << "\nWould you like to run the program again?" << endl;
		cin >> response;
		cout << endl;
	} while (response == 'y' || response == 'Y');

	return 0;
}

void questionAnswers(question i[], int count)
{
	cout << i[count].getQuestions() << endl;
	cout << i[count].getAnswer1() << endl;
	cout << i[count].getAnswer2() << endl;
	cout << i[count].getAnswer3() << endl;
	cout << i[count].getAnswer4() << endl << endl;
}


any and all help is appreciated
I think you're trying to create the class without ctor args somewhere. So you can either create a default ctor or pass arguments, or do both.
I'm a little confused by what you mean. I thought the constructor arguments was where it says:
1
2
3
4
5
6
7
8
9
question(string Q, string A1, string A2, string A3, string A4, int CA)		// Constructor
	{
		questions = Q;
		answer1 = A1;
		answer2 = A2;
		answer3 = A3;
		answer4 = A4;
		correctAnswer = CA;
	}


or am i missing something?
Yeah,
you must either create a default constructor(a ctor that takes no args) or pass the required args when declaring a type of your class.

Aceix.
You're probably creaing an object without passing arguments like:

 
question obj;


instead, it should be:

 
question obj("These", "Are", "Ctor", "Args", "D00d", 34);
all i did was add:
1
2
3
4
question::question()
	{
		correctAnswer = 0;
	}


into the class and it fixed it. lol
Last edited on
Fumbles93 wrote:
into the class and it fixed it. lol


Now the compiler has something to call upon object instantiation, I guess.
@ Bourgond Aries
normally i would have done that, but the problem needed an array.

Although, I probably could have done so anyways and just put the array into the main, instead of trying to call it from the class.
But then again, I'm not too sure how well that would have worked out.

In any case, thanks for all the suggestions everyone!
all i did was add:
question::question()
{
correctAnswer = 0;
}


That's what is called default constructor.

Aceix.
Topic archived. No new replies allowed.