Welcome to the VirtuQ Forums.
Results 1 to 4 of 4

Thread: Polymorphism

  1. #1

    Polymorphism

    Hi sir,
    What is polymorphism? How to explain it with respect to virtual functions and pure virtual functions? Can we call function overloading and operator overloading as polymorphism?

    Thank you.

  2. #2
    Hi sir,
    What is the use of virtual functions and purely virtual functions?
    Thank you.

  3. #3
    VirtuQ Moderator
    Join Date
    Jun 2011
    Location
    Bangalore, India
    Posts
    310
    Blog Entries
    4
    Anon10128,

    Polymorhism refers to inheriting or redefining functions of the base classes. This mechanism allows a programmer to define the communication interface through the base class and provide any number of implementations through derived classes. Since a derived class pointer is also a base class pointer, this mechanism enables to design the program via the base class pointers and pass on dervied class pointers for different implementations appropriately. At runtime, the function corresponding to actual passed object (dervied class or base class whichever was passed) will be called. In order to determine correct function at run-time, corresponding functions must be prefixed with virtual keyword. Further when a virtual function is declared to be null (no definition) in the base class, it is called a pure virtual function and corresponding base class is called abstract class. An object of the abstract class cannot be created.

    Polymorhism is different than the function (operator) overloading as the exact function to be called is decided at run time. On the other hand, function overloading results in different function signatures based on types which can be uniquely identified by the compiler at compile time.

    I would further suggest you to go through Polymorphism and overloading sections of C++ course for more examples.

    -- Basant

  4. #4


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •