I am not uderstanding difference between overiding andoverloading concept?

Recommended Answers

All 4 Replies

In function Overloading all function to be overridden have same function name but their data type and arguments differ from each other
while In overriding the function name, data type of funcions and there arguemts are same.

Example of function overloading
void getdata(int a,int b);
int getdata(int a,int b);
int getdata(int a,float b);
Example of function overriding
void getdata(int a,int b);
void getdata(int a,int b); 
virtual keyword

we use virtual keyword while overriding of functions so that let the compiler know which copy of function is to be called,may be you are knowing that one can't define same functions in a class so overriding is done by using inheritance

Two different concepts that unforunately seem similar due to the "over" part.

Overloading is when you have multiple functions that use the same name, but have different parameter lists. The function is said to be overloaded since calls that provide different arguments will call the correct function:

void foo() { cout << "No parameters\n"; }
void foo(int) { cout << "One parameter\n"; }

int main()
{
    foo();    // Prints "No parameters"
    foo(123); // Prints "One parameter"
}

Overriding is a concept related to polymorphism where a derived class' version of a member function is used instead of the base class' version. The derived class' function is said to override the base class' function:

class base {
public:
    virtual void foo() const { cout << "Base\n"; }
};

class derived: public base {
public:
    void foo() const override { cout << "Derived\n"; }
};

int main()
{
    const base& obj = derived();

    obj.foo(); // Prints "Derived"
}
commented: Well explained +14

sorry for disturbing but i've a question .

Example of function overloading

void getdata(int a,int b);
int getdata(int a,int b);

is this possible to perform overloading on the basis of their return type ?

i think NOT POSSIBLE.

is this possible to perform overloading on the basis of their return type ?

i think NOT POSSIBLE.

Correct, the return type doesn't contribute to the function's signature, and therefore you can't overload just on return type. Parameters and constness are the two biggies in terms of how a function signature is generated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.