473,395 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Diff btwn Function overloading and overriding

Hi,
What is the Diff btwn Function overloading and overriding

thanks,

a.a.cpp

Jul 23 '05 #1
11 8879
iceColdFire wrote:
Hi,
What is the Diff btwn Function overloading and overriding

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.
Jul 23 '05 #2
iceColdFire wrote:
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.

Jul 23 '05 #3
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.

Jul 23 '05 #4
Jaspreet wrote:

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.


It's a perfectly valid form of overloading, it just may be ill-formed
or ambiguous depending on the context.
Jul 23 '05 #5
Ron Natalie wrote:
Jaspreet wrote:

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.

It's a perfectly valid form of overloading,


No, it's not.
it just may be ill-formed or ambiguous depending on the context.


There is no context in which C++ allows function overloading only by return
type.

Jul 23 '05 #6
> 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.


It's a perfectly valid form of overloading, it just may be ill-formed
or ambiguous depending on the context.

I am using gcc 3.2.2 and it gives me the following error:
>>>>>new declaration `float area(int)'
>>>>>ambiguates old declaration `int area(int)'


Jul 23 '05 #7
Jaspreet wrote:
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.

It's a perfectly valid form of overloading, it just may be ill-formed
or ambiguous depending on the context.

I am using gcc 3.2.2 and it gives me the following error:
>>>>>>new declaration `float area(int)'
>>>>>>ambiguates old declaration `int area(int)'


And this counters what I said how?
Jul 23 '05 #8
Ron Natalie wrote:
Jaspreet wrote:

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.


It's a perfectly valid form of overloading, it just may be ill-formed
or ambiguous depending on the context.


Hi Ron
You mentioned it is a **perfectly valid form of overloading**. It is
not.

Jul 23 '05 #9
Ron Natalie wrote:
Jaspreet wrote:
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.

It's a perfectly valid form of overloading, it just may be ill-formed
or ambiguous depending on the context.

I am using gcc 3.2.2 and it gives me the following error:
>>>>>>>new declaration `float area(int)'
>>>>>>>ambiguates old declaration `int area(int)'

And this counters what I said how?


It doesn't. However, how about giving an example that proves your claim?

Jul 23 '05 #10
Jaspreet wrote:
Ron Natalie wrote:
Jaspreet wrote:

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.


It's a perfectly valid form of overloading, it just may be ill-formed
or ambiguous depending on the context.

Hi Ron
You mentioned it is a **perfectly valid form of overloading**. It is
not.

I said it can either be ill-formed or ambiguous DEPENDING ON THE
CONTEXT. In your example it's ill-formed. There are other cases
where it's not ill-formed to declare such, but it gets ambiguous
when you try to actually use it. [Put the two area's in different
namespaces and then bring them into the current namespace with USING].
Jul 23 '05 #11

Ron Natalie wrote:
I said it can either be ill-formed or ambiguous DEPENDING ON THE
CONTEXT. In your example it's ill-formed. There are other cases
where it's not ill-formed to declare such, but it gets ambiguous
when you try to actually use it. [Put the two area's in different
namespaces and then bring them into the current namespace with

USING].

Hi

I should have seen that. I forgot for once about using namespace.
Thanks..

Jul 23 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Susan Baker | last post by:
Hello everybody, I'm new to C++ (I have some C background). I've read up on this topic a few times but it just dosen't seem to be sinking in. 1. Whats the difference between overloading and...
3
by: Iyer, Prasad C | last post by:
I am new to python. I have few questions a. Is there something like function overloading in python? b. Can I overload __init__ method Thanks in advance regards
45
by: JaSeong Ju | last post by:
I would like to overload a C function. Is there any easy way to do this?
2
by: Edward Diener | last post by:
In C++ an overridden virtual function in a derived class must have the exact same signature of the function which is overridden in the base class, except for the return type which may return a...
7
by: asdf | last post by:
They looks so similar. Anybody would like to tell me their differences? Thanks a lot.
17
by: Rob Hoelz | last post by:
I've been compiling a list of the differences between C and C++, and I'd like to see how thorough I've been. Could any of you go over this list and see if I've missed anything? Here's the list:...
3
by: bb | last post by:
Hi, Why overriding "virtual void f(std::string)" as follows hides the "non- virtual void f(int)" ? compilation error C2664: 'D::f' : cannot convert parameter 1 from 'int' to 'std::string' ...
20
by: ramadeviirrigireddy | last post by:
Can anyone tell me whether the return type of the method will also be considered when you are overriding a method? what i mean exactly is whether the return type can be different when you are...
2
by: ciccio | last post by:
Hi, Ones more I have a stupid virtual function question. Assume the following simple lines of code class Parent { public: virtual Parent foo(Parent &); virtual void bar(Parent &); }
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.