Jan 25, 2018 at 6:19pm UTC
So, basically, I have a Question object with the constructor
Question(string question, string answer1, string answer2, string answer3, string answer4, int correct)
I call the Question objects by doing:
Question("question" , "option1" ... "option4" , 1),
Obviously this is not efficient whatsoever. So, i attempted to do:
Question(string question, string answersArray[4], int correct)
which works, but when I go to coding the trivia questions (it's a trivia game)
I do this but I get an error
Question("example question" , {"option1" , "option2" , "option3" , "option4" }, 1),
It's not a run time error it's an error on calling
1 2 3
Question questions[10] = {
Question ("" , {"answers" }, number)
}
The error says: no instance of constructor "Question::Question" matches the argument list
Last edited on Jan 25, 2018 at 7:14pm UTC
Jan 25, 2018 at 6:38pm UTC
So what happends if you change {" " ," " ..}
to closed brackets instead [" " , " " ]
Jan 25, 2018 at 6:46pm UTC
that does not work, unfortunately.
Jan 25, 2018 at 6:54pm UTC
Have another Question constructor, an overloaded constructor, that takes 3 parameters. 2 strings and an int. Your only declared constructor takes 6. 5 strings and an int.
See "overloading constructors" here:
http://www.cplusplus.com/doc/tutorial/classes/
Jan 25, 2018 at 7:00pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13
Question();
Question(param,param,param,param,param,param);
Question(String q, String a[], int c);
stuff
stuff
stuff
String q = "q" ;
String wat[2] = {"wat1" ,"wat2" };
int c = 666;
Question disMyQuestion = new Question(q,wat,c);
Last edited on Jan 25, 2018 at 7:00pm UTC
Jan 25, 2018 at 7:03pm UTC
I have 3 constructors, a default constructor and an overloaded constructor that takes a string, a string array and an int. I also have another constructor, like you suggested, that takes 2 strings and an int. I still get errors.
Jan 25, 2018 at 7:06pm UTC
What exactly are the errors?
Jan 25, 2018 at 7:11pm UTC
Ah. So my error was because I was instantiating it as a vector rather than an array of strings.
Question::Question(string q, vector<string> array, int correct)
did the trick!
Last edited on Jan 25, 2018 at 7:43pm UTC