By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,198 Members | 881 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,198 IT Pros & Developers. It's quick & easy.

difference betweeen overloading and overriding

P: n/a
#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

Apr 16 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
yashwant pinge wrote:
#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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 16 '07 #2

P: n/a
On Apr 16, 5:42 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
yashwant pinge wrote:
#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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
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...?

Apr 16 '07 #3

P: n/a
yashwant pinge wrote:
On Apr 16, 5:42 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>yashwant pinge wrote:
>>#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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 16 '07 #4

P: n/a
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.

Apr 17 '07 #5

P: n/a
Gaijinco wrote:
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?

--
Ian Collins.
Apr 17 '07 #6

P: n/a
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?

Apr 17 '07 #7

P: n/a
On Apr 17, 6:37 am, Gaijinco <gaiji...@gmail.comwrote:
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?
Apr 17 '07 #8

P: n/a
On Apr 17, 7:48 am, yashwant pinge
<yashwantpi...@gmail.comwrote:
On Apr 17, 6:37 am, Gaijinco <gaiji...@gmail.comwrote:
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?
I believe that's what FAQ 23.9 is all about.

http://www.parashift.com/c++-faq-lit....html#faq-23.9

--
Pavel Lepin

Apr 17 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.