您的位置:首页 > 编程语言 > C语言/C++

C++ function overriding

2015-12-31 13:11 435 查看
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.




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.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: