473,659 Members | 2,671 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8904
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)'
>>>>>ambigu ates 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)'
>>>>>>ambig uates 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:
>>>>>>>ne w declaration `float area(int)'
>>>>>>>ambi guates 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

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

Similar topics

15
24001
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 overriding? 2. When is one preferable to use as opposed to the other? 3. How are virtual functions related to this topic (overloading/overriding) - a real world example of using virtual functions would be very much appreciated.
3
2885
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
3269
by: JaSeong Ju | last post by:
I would like to overload a C function. Is there any easy way to do this?
2
2510
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 pointer or reference to a derived type of the base class's return type. In .NET the overridden virtual function is similar, but an actual parameter of the function can be a derived reference from the base class's reference also. This dichotomy...
7
6118
by: asdf | last post by:
They looks so similar. Anybody would like to tell me their differences? Thanks a lot.
17
1935
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: Mid-scope declarations Default function parameters new/delete operators Better implementation of const
3
2822
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' I know it will work if I bring it to the scope by B::f(). I just would like to know why does it hide just because am implementing a virtual
20
2949
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 overriding a method.and somewhere i read like overloading will not come under polymorphism. is this true?
2
1297
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
8427
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8332
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.