Overload and override in c++
来源:互联网 发布:手机网络枪战游戏排行 编辑:程序博客网 时间:2024/06/02 05:08
- Overload
C++ allow you to specify more than one definitions for a function name or an operator in the same scope,which is called function overloading and operator overloading respectively.
Consider the following example:
example one:
#include<iostream>using namespace std;class A{ int x;public: void print(){std::cout<<"print:1"<<endl;} void print(int a){std::cout<<"print int:"<<a<<endl;} void print(double a){std::cout<<"print double:"<<a<<endl;} //conflict with void print(double) //double print(double a){return a;}};int main(int argc, char *argv[]){ A* a = new A; a->print(); a->print(2); a->print(300.00); /* A a; a.print(); a.print(2); a.print(300.243); */ return 0;}
There are three elements in function overload:
- in the same scope
- the same function name
- different arguments
example two
contents about operator overloading will be fullfilled int he future.
- Override
C++ allow you to override a virtual method of the base class, which has a key word “virtual” in front.
Consider the following example:
#include<iostream>using namespace std;class A{ int x;public: virtual void func(){}};class B:A{ int y;public: void func() {cout<<"overriding"<<endl;}};int main(int argc, char*argv[]){ B* b = new B(); b->func(); return 0;}
阅读全文
0 0
- Override and Overload in Java
- Overload and override in c++
- overload and override
- Overload, Override and Overwrite
- java override and overload
- Overload, Override and Overwrite
- overload, override, and redefine
- C++:overload, override和overwrite
- override overload hide and their differences
- The Difference of Override and Overload
- 重载与重写(overload and override)
- 重载和重写(overload and override)
- 覆盖与重载(override/overload) [C#]
- overload,override
- overload override
- override overload
- override overload
- overload与override的区别 What is the difference between overload and override
- 通过进程令牌启动新的进程
- RIDE底部的日志没显示怎么办?
- 异步I/O(4)完成端口
- hadoop--23
- JAVA 入门篇
- Overload and override in c++
- 浅谈js回调函数
- timestamp (Transact-SQL)
- 为什么那么多人说C++难学?怎么学
- 《Spring Cloud Netflix》--服务注册和服务发现-Eureka的深入了解
- SQL Server查看所有表大小,所占空间
- LeetCode-46. Permutations +组合实现
- android采集视频格式转换算法
- LA-3211-TwoSAT,二分