When another class (like Student) wants to provide a different implementation for a virtual member function, like toString(), it must:
Let's override toString() in the Student class. Here's the header:
class Student : public Person
{
public:
Student(const std::string name, long sid);
long getID() const;
std::string toString() const override;
private:
long studentID;
};
Note that the prototype is copied exactly from Person::toString(), except for the keyword virtual. You do not need to repeat the word virtual in the derived class definition, (although you may for documentation purposes). A virtual function is always virtual, and a non-virtual function cannot be made virtual in one of its subclasses.