iceColdFire wrote:[color=blue]
> Hi,
> What is the Diff btwn Function overloading and overriding
>[/color]
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();
};
iceColdFire wrote:
[color=blue]
> Hi,
> What is the Diff btwn Function overloading and overriding[/color]
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.
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.
Jaspreet wrote:
[color=blue]
>
> 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.
>[/color]
It's a perfectly valid form of overloading, it just may be ill-formed
or ambiguous depending on the context.
Ron Natalie wrote:
[color=blue]
> Jaspreet wrote:
>[color=green]
>>
>> 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.
>>[/color]
>
> It's a perfectly valid form of overloading,[/color]
No, it's not.
[color=blue]
> it just may be ill-formed or ambiguous depending on the context.[/color]
There is no context in which C++ allows function overloading only by return
type.
> However,[color=blue]
> int area(int side);
> float area(int length);
> are not valid examples of overloading since the signature is the same[/color]
[color=blue]
> and the only difference is in the return type.[/color]
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:[color=blue][color=green][color=darkred]
>>>>>>>>>new declaration `float area(int)'
>>>>>>>>>ambigu ates old declaration `int area(int)'[/color][/color][/color]
Jaspreet wrote:[color=blue][color=green]
>>However,
>>int area(int side);
>>float area(int length);
>>are not valid examples of overloading since the signature is the same[/color]
>
>[color=green]
>>and the only difference is in the return type.[/color]
>
>
> 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:
>[color=green][color=darkred]
>>>>>>>>>>new declaration `float area(int)'
>>>>>>>>>>ambig uates old declaration `int area(int)'[/color][/color]
>
>[/color]
And this counters what I said how?
Ron Natalie wrote:[color=blue]
> Jaspreet wrote:
>[color=green]
> >
> > However,
> > int area(int side);
> > float area(int length);
> >
> > are not valid examples of overloading since the signature is the[/color][/color]
same[color=blue][color=green]
> > and the only difference is in the return type.
> >[/color]
>
> It's a perfectly valid form of overloading, it just may be ill-formed
> or ambiguous depending on the context.[/color]
Hi Ron
You mentioned it is a **perfectly valid form of overloading**. It is
not.
Ron Natalie wrote:
[color=blue]
> Jaspreet wrote:[color=green][color=darkred]
>>>However,
>>>int area(int side);
>>>float area(int length);
>>>are not valid examples of overloading since the signature is the same[/color]
>>
>>[color=darkred]
>>>and the only difference is in the return type.[/color]
>>
>>
>> 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:
>>[color=darkred]
>>>>>>>>>>>ne w declaration `float area(int)'
>>>>>>>>>>>ambi guates old declaration `int area(int)'[/color]
>>[/color]
> And this counters what I said how?[/color]
It doesn't. However, how about giving an example that proves your claim?
Jaspreet wrote:[color=blue]
> Ron Natalie wrote:
>[color=green]
>>Jaspreet wrote:
>>
>>[color=darkred]
>>>However,
>>>int area(int side);
>>>float area(int length);
>>>
>>>are not valid examples of overloading since the signature is the[/color][/color]
>
> same
>[color=green][color=darkred]
>>>and the only difference is in the return type.
>>>[/color]
>>
>>It's a perfectly valid form of overloading, it just may be ill-formed
>>or ambiguous depending on the context.[/color]
>
>
> Hi Ron
> You mentioned it is a **perfectly valid form of overloading**. It is
> not.
>[/color]
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].
Ron Natalie wrote:[color=blue]
> 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[/color]
USING].
Hi
I should have seen that. I forgot for once about using namespace.
Thanks..
Comment