GeekInterview.com
Results 1 to 4 of 4

c++

This is a discussion on c++ within the C and C++ forums, part of the Software Development category; what is fuanction overriding?...

  1. #1
    timirbls is offline Junior Member Array
    Join Date
    May 2008
    Answers
    2

    c++

    what is fuanction overriding?


  2. #2
    lipune is offline Junior Member Array
    Join Date
    May 2008
    Answers
    4

    Re: c++

    function overidding is noting but a function have same name which present in both base class and derive class,we use virtual mechanisim in function overridding,but overloading occur between a class.not in 2different class.ok


  3. #3
    Sandhya.Kishan is offline Expert Member Array
    Join Date
    Mar 2012
    Answers
    212

    Re: c++

    Function overriding enables us to write multiple functions with the same name.The compiler differentiates the function depending on the number of and types of the parameters the function takes.

    Example
    Class num
    {
    int sum();
    int sum(int i, int j);
    int sum=i+j; return(sum);
    }


  4. #4
    jbode is offline Contributing Member Array
    Join Date
    Jun 2010
    Answers
    56

    Re: c++

    There is a difference between function overloading and function overriding.

    You can overload a function or method by declaring or defining multiple functions or methods with the same name in the same scope, but with different signatures:

    Code:
    int foo(void);
    int foo(int);
    int foo(double);
    void foo(int, int);
    The compiler figures out which of these to call based on the number and types of parameters; if you write foo(), the first version will be called. If you write foo(3.14159), then the third version will be called.

    You can override a method by inheriting it from a base class, then changing the implementation in the child class:

    Code:
    class base {
    public:
      void foo() { cout << "in base::foo" << endl; }
    };
    
    class derived : public base {
    public:
      void foo() { cout << "in derived::foo" << endl; }
    };
    The definition of foo in derived overrides the definition in base. The method signature (return type and parameters) is the same between the parent and child class, but the implementation in the child class is different, and they occur in different scopes.

    Hopefully that made sense.


    •    Sponsored Ads