about-text

SoftOSet is the most remarkable programming site. SoftOSet provides the fresh conceptual and professional programs, articles, books, and other interesting and technical writings. SoftOSet is the most reliable programming site to learn the programs and the basics of the popular programming languages. SoftOSet is the hub of the informative and research based articles.

Polymorphism Pointer to object in C++ Program


The word polymorphism is derived from two words poly and morphism.

Poly means many and morphism means form.

Ø  Polymorphism is the ability of the objects of different types to respond the  function of same  name

But according to the advanced concepts

Ø  The Process of Accessing Same Name  Functions of the Child Class with Help of Pointer of the Parent Class and the Virtual Function is called as Polymorphism

 

Pointer to object

 

Ø  Pointer is a variable which stores the address of the other variable

Ø  The Pointer which stores the address of the object is Pointer to object

Ø  Normal behaviour of  Pointer : Store address of same  data types

Ø  Polymorhism behaviour : Store address of different data types

Ø  Syntax : ptr->member

 

 Code

#include<iostream>

using namespace std;

class Pakistan{

private:

             int cities;                                                                   

public:                                                                        

            void get()                                                                       

            {                                                                           

            cout<<"Enter The Total Number of Cities of Pakistan : ";         

            cin>>cities;                                                          

            }                                                                         

            void show()                                      

            {

            cout<<"Total Cities of Pakistan = "<<cities<<endl;                      

            }                                                                      

};         

int main()      

{                                              

Pakistan  *ptr;           

ptr=new Pakistan;

  ptr->get();

ptr->show();

return 0;

}

 

 

Output

And here is the sample output of this code. If you have any error about the code then contact us. We will surely help you to run your code and resolve your error.

 


 

 

Conclusion

Now I conclude the whole story in a single sentence

“Polymorphism is used to access the functions using the pointers.”

If you have any type of bug or error in your code feel free to take guidance from us. Our team will try its best to help you to remove your bug.

 

Thank you

 

 

 

 

 

 


Post a Comment

Feel Free to Comment Us

Previous Post Next Post

Recents