Results 1 to 4 of 4

Thread: c++

  1. #1
    Junior Member
    Join Date
    May 2008
    Answers
    2

    c++

    what is fuanction overriding?


  2. #2
    Junior Member
    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
    Expert Member
    Join Date
    Mar 2012
    Answers
    208

    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
    Contributing Member
    Join Date
    Jun 2010
    Answers
    55

    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact