Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Diff btwn Function overloading and overriding

Reply
Thread Tools

Diff btwn Function overloading and overriding

 
 
iceColdFire
Guest
Posts: n/a
 
      05-14-2005
Hi,
What is the Diff btwn Function overloading and overriding

thanks,

a.a.cpp

 
Reply With Quote
 
 
 
 
Ron Natalie
Guest
Posts: n/a
 
      05-14-2005
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.
 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      05-14-2005
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.

 
Reply With Quote
 
Jaspreet
Guest
Posts: n/a
 
      05-16-2005
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.

 
Reply With Quote
 
Ron Natalie
Guest
Posts: n/a
 
      05-16-2005
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.
 
Reply With Quote
 
Rolf Magnus
Guest
Posts: n/a
 
      05-16-2005
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.

 
Reply With Quote
 
Jaspreet
Guest
Posts: n/a
 
      05-17-2005
> 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)'


 
Reply With Quote
 
Ron Natalie
Guest
Posts: n/a
 
      05-17-2005
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?
 
Reply With Quote
 
Jaspreet
Guest
Posts: n/a
 
      05-17-2005
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.

 
Reply With Quote
 
Ron Natalie
Guest
Posts: n/a
 
      05-17-2005
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].
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
difference btwn AMD and Intel processors davis.angwenyi@gmail.com A+ Certification 2 04-26-2007 04:46 AM
Difference btwn Servlet and Web Service Shinya Koizumi Java 3 04-29-2006 05:21 AM
diff Process under diff users Cyril Vi?ville Perl 1 06-29-2004 06:22 PM
What is the diff btwn 'sho proc' and 'sho proc cpu' William J King Cisco 1 12-18-2003 11:50 PM
Same sessionID retuned to diff browsers in diff machines Berrucho ASP .Net 2 12-05-2003 02:23 PM



Advertisments