Emailid
Password
         
  
    Forgot password

New user Sign Up
 

Polymorphism _ a special type

       Current Rating:  0%                                                     Total Members Rated:  0
                                                                     Send To Friend

  

Polymorphism _ a special type

 

 

Introduction

 

Polymorphism is a special type one which is used in programs. Polymorphism in C++ is usually regarded as always implemented in the form of class hierarchies containing virtual member functions.

 

Object of a developed class

 

It will be from the actual type of the object that was allocated, rather than the static type that the base class pointer or reference is declared. An object of a derived class can be supplied to create a pointer or reference to what is apparently the base class; a function pointer lookup in the vtbl is done when calling a virtual member function off a pointer or reference, so that the function called will be based on the dynamic type that the pointer or reference denotes.

 

Meaning

 

 The idea of polymorphism can have a more general meaning than that, and I have seen mailing list postings advocating that it should also include the use of templates that allow source code with identical syntax to be applied to objects of unrelated types. This std::vector can be regarded as a polymorphic container that is parameterized by the type supplied as a parameter when a vector object is declared.

 

Pointers

 

In the regular type, we determine which member function ultimately gets called by allocating objects of different types, that are related members in an inheritance tree. Pointers to member functions can be used to implement a different kind of polymorphism. This is implemented by having the vptr that is a hidden member of the object point at the appropriate vtbl. And thus it is useful.

 

Conclusion

 

Here, in this form you create objects that are always of the same type, but determine which member function gets called by choosing which member function's address gets assigned to a member function pointer. One interesting advantage is that you can change the behavior of an object during its lifetime without having to allocate a new one of a different type as you would with the regular sort of inheritance-based polymorphism. Polymorphism is efficient in many program tasks.

 


                           Rate This Article:   

Author is Offline
  Author: Hilda Wasah
       


Comments Posted
Label
Subject Author Status Date

 

Post Comment

Related Articles
Fundamentals on .NET Framework
N-Tier in ASP.NET or other .NET apps
Software Development Outsourcing (Offshore ) to India
Make your web site ‘perfect and Search Engine Friendly for Google and Yahoo
Color combination of your Web site



Home | About Us | Site Map | Privacy Policy | Submit Links