difference betweeen overloading and overriding

Discussion in 'C++' started by yashwant pinge, Apr 16, 2007.

  1. #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
    yashwant pinge, Apr 16, 2007
    #1
    1. Advertising

  2. 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
    Victor Bazarov, Apr 16, 2007
    #2
    1. Advertising

  3. On Apr 16, 5:42 pm, "Victor Bazarov" <> 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...?
    yashwant pinge, Apr 16, 2007
    #3
  4. yashwant pinge wrote:
    > On Apr 16, 5:42 pm, "Victor Bazarov" <> 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
    Victor Bazarov, Apr 16, 2007
    #4
  5. yashwant pinge

    Gaijinco Guest

    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.
    Gaijinco, Apr 17, 2007
    #5
  6. yashwant pinge

    Ian Collins Guest

    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.
    Ian Collins, Apr 17, 2007
    #6
  7. yashwant pinge

    Gaijinco Guest

    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?
    Gaijinco, Apr 17, 2007
    #7
  8. On Apr 17, 6:37 am, Gaijinco <> 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?
    yashwant pinge, Apr 17, 2007
    #8
  9. yashwant pinge

    Guest

    On Apr 17, 7:48 am, yashwant pinge
    <> wrote:
    > On Apr 17, 6:37 am, Gaijinco <> 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-lite/strange-inheritance.html#faq-23.9

    --
    Pavel Lepin
    , Apr 17, 2007
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Don Bruder
    Replies:
    12
    Views:
    663
    Chris Uppal
    Aug 3, 2005
  2. Xiangliang Meng
    Replies:
    1
    Views:
    1,592
    Victor Bazarov
    Jun 21, 2004
  3. iceColdFire
    Replies:
    11
    Views:
    13,310
    Jaspreet
    May 18, 2005
  4. yogesh
    Replies:
    0
    Views:
    273
    yogesh
    Apr 23, 2008
  5. john
    Replies:
    2
    Views:
    563
    Beej Jorgensen
    Jan 9, 2010
Loading...

Share This Page