Help, am a c++ student who is completely stuck. I know that there are some stupid errors in this, I've been working all day on this and I still can't find them. I'm supposed to create a class, copy constructor, and than create an instance in main and then create an array of objects from this class. I can't even get the constructor to instantiate, and the function called from main doesn't recognize any of the variables declared in the class. What am I doing wrong? Please help.
First of all, your class needs at least a default constructor. Something to tell the computer how to make a question and what default values to use. It could be something like
where you tell it the default values, or something like
Question(string quest, string answers[], int correct[], int numquest, int num, int n)
where the programmer provides all the default values, or something in between.
Second of all, I think you're getting your Copy Constructor and Constructor mixed up. The Copy Constructor should only be used when you are copying one Question to another, not when you create a new instance. It looks like you've got a mash up of your Constructor and Copy Constructor.
Third, quest and n are not defined in your program. They are private variables in the class, and cannot be accessed except by the code for the class. If you want access to them, you have to write functions in your class to do so, such as
which would then be accessed through your Questions variable.
Which brings me to my next point: enterquestion is a function in the Question class. It cannot be accessed as you're doing it. It should be accessed like so:
All member functions need to be accessed through a variable of the class using the . operator.
Finally, you never initialize your fstream in main. What file is it reading? I see you initialize it in the readfile function in the class, but then there's no point to passing an fstream as an argument if you don't use it.
If you fix these 5 things, it should run. I think you should reread your notes on classes.