virtual function

Discussion in 'C++' started by mahati, Oct 2, 2017.

  1. mahati

    mahati New Member

    Joined:
    Jun 30, 2012
    Messages:
    3
    Likes Received:
    1
    Trophy Points:
    1
    Hi,
    I am learning Virtual function in c++. I read Virtual function is member function that is used to achieve run time polymorphism. It is known that polymorphism means one name but multiple forms.But how run time polymorphism(i.e;one name multiple forms) is achieved through virtual function?

    Please help me in understanding the concept.

    Also,RUNTIME TIME POLYMORPHISM and METHOD OVERRIDING are synonyms?
     
    swathi krishna likes this.
  2. persysweb

    persysweb Member

    Joined:
    Aug 1, 2017
    Messages:
    98
    Likes Received:
    18
    Trophy Points:
    8
    Location:
    India
    Home Page:
    httpS://persys.in/
    Run time polymorphisam and function overriding are the same concepts. The same method with same parameters or signature, but associated in a class & its subclass is called the polymorphism or overriding.

    Overriding is when you call a method on an object and the method in the subclass with the same signature as the one in the superclass is called.

    Polymorphism is where you are not sure of the objects type at runtime and the most specific method is called. Therefore the behaviour of the method called may differ, depending on the objects type at runtime.

    Overriding is a type of polymorphism along with overloading and dynamic (late) binding.
     
  3. mahati

    mahati New Member

    Joined:
    Jun 30, 2012
    Messages:
    3
    Likes Received:
    1
    Trophy Points:
    1
    @persysweb,
    then, What is relationship between method overriding and virtual function?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice