Diff btwn函数重载和覆盖 [英] Diff btwn Function overloading and overriding

查看:83
本文介绍了Diff btwn函数重载和覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



什么是Diff btwn函数重载和覆盖


谢谢,


aacpp

Hi,
What is the Diff btwn Function overloading and overriding

thanks,

a.a.cpp

推荐答案

iceColdFire写道:
iceColdFire wrote:

什么是Diff btwn函数重载和覆盖
Hi,
What is the Diff btwn Function overloading and overriding



重载是指选择多个函数签名

同名:

A(int x);

A(std :: string s);

A(双d);

重载函数名称A.


覆盖是指与基类中的

虚拟函数具有相同签名的函数:

class B {

虚拟空虚V();

};


D类:公共B {

viod V();

};


D :: V覆盖B :: V。


Overloading refers to the selection of multiple signatures of functions
of the same name:
A(int x);
A(std::string s);
A(double d);
is overloading the function name A.

Overriding refers to functions that have the same signature as a
virtual function in the base class:
class B {
virtual void V();
};

class D : public B {
viod V();
};

D::V overrides B::V.


iceColdFire写道:
iceColdFire wrote:

什么是Diff btwn函数ov erloading and overriding
Hi,
What is the Diff btwn Function overloading and overriding




是的。它们是两个完全不同的概念。重载意味着你可以

有几个不同的函数同名。

覆盖意味着在几个函数中,正确一个被选中

运行类型,具体取决于对象的动态类型。



Yes. They are two totally different concepts. Overloading means that you can
have several different functions with the same name.
Overriding means that out of several functions, the ''right'' one is selected
at run-type depending on the dynamic type of an object.


您好


函数重载是指具有相同的函数名称和

不同的签名。

记住签名只是引用参数的数量和类型。

返回类型无关紧要。

Soo,


int area(int side);

int area(int length, int wideth);

int area(int length,int widthth,int height);


是重载的有效示例。

但是,

int area(int side);

浮动区域(int length);


是不是有效的重载示例,因为签名是相同的

,唯一的区别在于返回类型。

Hi

Function overloading is when you have same function names with
different signatures.
Remember the signature just refers to the number and type of arguments.
The return type does not matter.
Soo,

int area(int side);
int area(int length, int breadth);
int area(int length, int breadth, int height);

are valid examples of overloading.

However,
int area(int side);
float area(int length);

are not valid examples of overloading since the signature is the same
and the only difference is in the return type.


这篇关于Diff btwn函数重载和覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆