Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > difference betweeen overloading and overriding

Reply
Thread Tools

difference betweeen overloading and overriding

 
 
yashwant pinge
Guest
Posts: n/a
 
      04-16-2007
#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

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      04-16-2007
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


 
Reply With Quote
 
 
 
 
yashwant pinge
Guest
Posts: n/a
 
      04-16-2007
On Apr 16, 5:42 pm, "Victor Bazarov" <(E-Mail Removed)> wrote:
> 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...?

 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      04-16-2007
yashwant pinge wrote:
> On Apr 16, 5:42 pm, "Victor Bazarov" <(E-Mail Removed)> wrote:
>> 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


 
Reply With Quote
 
Gaijinco
Guest
Posts: n/a
 
      04-17-2007
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.

 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      04-17-2007
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.
 
Reply With Quote
 
Gaijinco
Guest
Posts: n/a
 
      04-17-2007
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?

 
Reply With Quote
 
yashwant pinge
Guest
Posts: n/a
 
      04-17-2007
On Apr 17, 6:37 am, Gaijinco <(E-Mail Removed)> wrote:
> 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?


 
Reply With Quote
 
p.lepin@ctncorp.com
Guest
Posts: n/a
 
      04-17-2007
On Apr 17, 7:48 am, yashwant pinge
<(E-Mail Removed)> wrote:
> On Apr 17, 6:37 am, Gaijinco <(E-Mail Removed)> wrote:
>
> > 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
process Id and HINSTANCE...what is the relation betweeen them? john C Programming 2 01-09-2010 10:37 PM
Mapping Templates function betweeen 2 class yogesh C++ 0 04-23-2008 08:02 PM
How compatible is Java betweeen versions? Don Bruder Java 12 08-03-2005 12:36 PM
Diff btwn Function overloading and overriding iceColdFire C++ 11 05-18-2005 06:12 AM
please help me in distinguish redefining functions, overloading functions and overriding functions. Xiangliang Meng C++ 1 06-21-2004 03:11 AM



Advertisments