Computer Science 1037A/B Lecture 35: Overriding Base Class Functions
Document Summary
Overriding: function in a derived class that has the same name and parameter list as a function in the base class. Typically used to replace a function in base class with different actions in derived class. Not the same as overloading with overloading, the parameter lists must be different. When a function is overridden, all objects of derived class use the overriding function. If necessary to access the overridden version of the function, it can be done using the scope resolution operator with the name of the base class and the name of the function: #include using namespace std; inheritance. h enum discipline { archeology, biology, computer_science }; enum classification { freshman, sophomore, junior, senior }; class person protected: string name; public: Person(string pname) { setname(pname); } void setname(string pname) { name = pname; } string getname() { return name; } class student:public person private: Student(string sname, discipline d, person *adv); void setmajor(discipline d) { major = d; }