difference betweeen overloading and overriding

Y

yashwant pinge

#include<iostream>
using namespace std;

class base
{
public:
void display()
{
}
};

class derived : public base
{
public:
void display(int i )
{
}
};

int main()
{
derived d;
d.display(1);
}


can anyone tell me that display funcion in derived class is a
overriding function or overloading function
 
V

Victor Bazarov

yashwant said:
#include<iostream>
using namespace std;

class base
{
public:
void display()
{
}
};

class derived : public base
{
public:
void display(int i )
{
}
};

int main()
{
derived d;
d.display(1);
}


can anyone tell me that display funcion in derived class is a
overriding function or overloading function

Neither.

Overloading concerns names in the same scope. Derived class'
scope is different than the base class' scope.

Overriding concerns virtual functions. There are no virtual
functions in your example.

V
 
Y

yashwant pinge

Neither.

Overloading concerns names in the same scope. Derived class'
scope is different than the base class' scope.

Overriding concerns virtual functions. There are no virtual
functions in your example.

V

But the derived class is inherited from the base class .
As per the concepts of inheritance all the functions in base class is
inherited in the derived class so the derived class cotains the two
functions display with no parameters and with int parameter

so is it overloading functions in derived class...?
 
V

Victor Bazarov

yashwant said:
But the derived class is inherited from the base class .

The proper term is either "is derived from" or "inherits from" or
"derives from".
As per the concepts of inheritance all the functions in base class is
inherited in the derived class so the derived class cotains the two
functions display with no parameters and with int parameter

I am not sure what you mean by "contains".
so is it overloading functions in derived class...?

No, it is not (see my explanantion above). The 'base::display' member
is _hidden_ in 'derived'. Without special actions, the 'display' with
no arguments is not callable with/from 'derived'.

V
 
G

Gaijinco

As I understand it, class derived has two functions "display" because
they have a diffent signature. Overriding a function implies that the
method has the same signature but different implementation.
 
I

Ian Collins

Gaijinco said:
As I understand it, class derived has two functions "display" because
they have a diffent signature. Overriding a function implies that the
method has the same signature but different implementation.
Understand what?
 
G

Gaijinco

Oh yeah I was very wrong, I tried to code some examples and the
compiler always said that display() from "base" is not accessible from
"derived" but I don't understand something: Can I overload a method
that was inherited?
 
Y

yashwant pinge

Oh yeah I was very wrong, I tried to code some examples and the
compiler always said that display() from "base" is not accessible from
"derived" but I don't understand something: Can I overload a method
that was inherited?


test.cpp: In function `int main()':
test.cpp:27: no matching function for call to `derived::display()'
test.cpp:18: candidates are: void derived::display(int)

Why it should be?
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top