fastread homefastrread library fastread menu

C++ : Function Overriding

Tutorial by:Manisha Dubey      Date: 2016-06-18 01:07:21

❰ Previous Next ❱

If base class and derived class have member functions with same name and arguments. If you create an object of derived class and write code to access that member function then, the member function in derived class is only invoked, i.e., the member function of derived class overrides the member function of base class. This feature in C++ programming is known as function overriding.

Example to demonstrate function overriding in C++ programming

Accessing the Overridden Function in Base Class From Derived Class

To access the overridden function of base class from derived class, scope resolution operator ::. For example: If you want to access get_data() function of base class from derived class in above example then, the following statement is used in derived class.

A::get_data; // Calling get_data() of class A.



It is because, if the name of class is not specified, the compiler thinks get_data() function is calling itself.

User of scope resolution operator in overridden function

❰ Previous Next ❱


Submit Your Thought, Tutorial, Articls etc.

Submit Your Information India's Number one online promotion website