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.
To access the overridden function of base class from derived class, scope resolution operator ::. For example: If you want to access
of base class from derived class in above example then, the following statement is used in derived class.
It is because, if the name of class is not specified, the compiler thinks
is calling itself.
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.
相关文章推荐
- Bag of Words cpp实现(stable version 0.01)
- C++面试一
- [转载] Memory Layout of C programs
- 面向对象分析与设计(C++)课堂笔记
- 将Faster RCNN的python demo改成C++ demo
- C++字符串格式化(FormatString)
- PCL库和C++2011兼容问题
- 转载——C++控制台贪吃蛇代码
- C++中智能指针的工作原理和简单实现
- C/C++ 输入一个数 判断是否是素数
- 【C++】基础知识—内联(置)函数及register关键字
- C++中的基类与派生类
- 聚类算法-Hierarchical(MIN)-C++
- Java调用C/C++代码-生成java调用的DLL
- 聚类算法-K-means-C++实现
- C/C++ 随机数
- VC++中通过MultiByteToWideChar将string|char*转换为wstring|wchar_t*
- 聚类算法-DBSCAN-C++实现
- 表达式求值c语言
- iOS OC语言: Block底层实现原理 (转载)