Redefining Access with using
Public members of a base class become protected or private when you use protected or private derivation. Suppose you want to make a particular base-class method available publicly in the derived class. One option is to define a derived-class method that uses the base-class method. For example, suppose you want the Student
class to be able to use the valarray sum()
method. You can declare a sum()
method in the class declaration and then define the method this way:
double Student::sum() const // public Student method{ return std::valarray<double>::sum(); // use privately-inherited method}
Then a Student
object can invoke Student::sum()
, which, in turn, applies the valarray<double>::sum()
method to the embedded ...
Get C++ Primer Plus now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.