Diff btwn Function overloading and overriding

R

Ron Natalie

iceColdFire said:
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.
 
R

Rolf Magnus

iceColdFire said:
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.
 
J

Jaspreet

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.
 
R

Ron Natalie

Jaspreet said:
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.
 
J

Jaspreet

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:
 
R

Ron Natalie

Jaspreet said:
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:
And this counters what I said how?
 
J

Jaspreet

Ron said:
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.
 
R

Ron Natalie

Jaspreet said:
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].
 
J

Jaspreet

Ron said:
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..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top