Cpp - Calling the Base Member Function

Introduction

To access the overridden base member function, write the base name, followed by two colons, and then the function name. For example:

Mammal::move() 

Demo

#include <iostream> 
   //from   w  w w.ja v  a 2  s .c  o  m
class Mammal 
{ 
public: 
    void move() const { std::cout << "Mammal moves one step\n"; } 
    void move(int distance) const  
           { std::cout << "Mammal moves " << distance << " steps\n"; } 
protected: 
    int age; 
    int weight; 
}; 
   
class Dog : public Mammal 
{ 
public: 
    void move() const; 
}; 
   
void Dog::move() const 
{ 
    std::cout << "Dog moves ...\n"; 
    Mammal::move(3); 
} 
   
int main() 
{ 
    Mammal bigAnimal; 
    Dog fido; 
    bigAnimal.move(2); 
    fido.Mammal::move(6); 
    return 0; 
}

Result

Related Topic