I am getting quite a bit confused, to me I think the following two implementation are valid (but my syntax has error), but I can not get either one of them to work. This is a year 1 C++ intro class homework, we can not use Vector (or else it will be done a long time ago...)
I already finished my class Student, but now I have to create a container to store n students.
I was thinking the following two option.
1) Create an array of student objects: Student arrayOfStudents[20];
My student class is very simple (It is modified different because too many lines). But the idea is like this...
class Student
{
public:
// Constructor for the Book class, take 6 arguments
Student(string myUID, string myLastName, string myFirstName,
string major, string age, string homeState, bool isWorking);
...
};
But when I try to create an array of students, I get this error message.
cs114p2main.cpp: In function ‘int main(int, char**)’:
cs114p2main.cpp:103: error: no matching function for call to ‘Student::Student()’
cs114p2Student.h:14: note: candidates are: Student::Student(std::string*)
cs114p2Student.h:11: note: Student::Student(std::string, std::string, std::string, std::string, std::string, bool)
cs114p2Student.h:7: note: Student::Student(const Student&)
2) Also tried: Create an array of student pointer that points to each student.
Student* ArrayOfStudents = Student[20];
My question is why doesn't the method 1 work? And do I have to use pointers in this case (something along the line of method 2).
Because I need to pass this array into a function that going to set up each student. (I do not know how many students are going to be there). So does that mean I have to pass a pointer to the array of students? In that case I really hope method 1 can work, I can't imagine dealing with pointer to array of student pointers. I was thinking have to return an array of data[numOfData][numOfStudnet], and do it in the main, but either way I would like to figure out why this gives me error.. thank you.
Edit: Follwo up question : I know through research, I must declare the size of the array of Student as the parameter, but what if I only know the size after it is running? In that case, what are my options?