My parent class, Course, has the method addStudent(Student s). My child class, BetterCourse, inherits from Course. Every time I try to run BetterCourse.addStudent(s), I get the following error:
error: no matching function for call to ‘BetterCourse::addStudent(Student (&)())’
note: candidates are: void Course::addStudent(Student)
I understand it's telling me addStudent() hasn't been defined in BetterCourse and that it's recommending I use the one present in the parent class, Course. This has me confused as the whole idea around inheritance is not needing to redefine inherited functions and variables.
I understand it's telling me addStudent() hasn't been defined in BetterCourse and that it's recommending I use the one present in the parent class, Course.
No, that's not what it says. It says that you are trying to pass a function (that takes no arguments and returns a Student) as argument to BetterCourse::addStudent.
Sorry, I pasted output that resulted from me trying to add the addStudent function to BetterCourse. I've fixed the post to reflect that it actually specifies addStudent() from Course.
I was creating a student with an empty constructor, which while technically defined in Student (see below), is not accounted for in Course.addStudent().
1 2 3 4 5 6 7 8 9
Student::Student(){
id = "";
name = "";
}
Student::Student(string id, string name){
this->id = id;
this->name = name;
}
I have added the required parameters and I no longer get the error. I am now going to give in to sleep.
I've always wondered, why is it even legal to have a function declaration in the scope of a function? I've also always been confused by class/namespace scope vs function scope, how they're the same/different.