Differentiate between function overloading and fun

2019-01-08 06:13发布

Differentiate between function overloading and function overriding in C++?

11条回答
甜甜的少女心
2楼-- · 2019-01-08 06:41

Function overloading is same name function but different arguments. Function over riding means same name function and same as arguments

查看更多
迷人小祖宗
3楼-- · 2019-01-08 06:44

Function overloading - functions with same name, but different number of arguments

Function overriding - concept of inheritance. Functions with same name and same number of arguments. Here the second function is said to have overridden the first

查看更多
别忘想泡老子
4楼-- · 2019-01-08 06:46

1.Function Overloading is when multiple function with same name exist in a class. Function Overriding is when function have same prototype in base class as well as derived class.

2.Function Overloading can occur without inheritance. Function Overriding occurs when one class is inherited from another class.

3.Overloaded functions must differ in either number of parameters or type of parameters should be different. In Overridden function parameters must be same.

For more detail you can visit below link where you get more information about function overloading and overriding in c++ https://googleweblight.com/i?u=https://www.geeksforgeeks.org/function-overloading-vs-function-overriding-in-cpp/&hl=en-IN

查看更多
劳资没心,怎么记你
5楼-- · 2019-01-08 06:48

Function overloading is done when you want to have the same function with different parameters

void Print(string s);//Print string
void Print(int i);//Print integer

Function overriding is done to give a different meaning to the function in the base class

class Stream//A stream of bytes
{
public virtual void Read();//read bytes
}

class FileStream:Stream//derived class
{
public override void Read();//read bytes from a file
}
class NetworkStream:Stream//derived class
{
public override void Read();//read bytes from a network
}
查看更多
爷的心禁止访问
6楼-- · 2019-01-08 06:49

Overloading means having methods with same name but different signature Overriding means rewriting the virtual method of the base class.............

查看更多
我欲成王,谁敢阻挡
7楼-- · 2019-01-08 06:50

In addition to the existing answers, Overridden functions are in different scopes; whereas overloaded functions are in same scope.

查看更多
登录 后发表回答