Is it possible to create a pointer to a class in C++?

Yes, we can create a pointer to a class and can access data-members or call member-functions of the class.

 

For example :

#include <iostream.h>
class Demo
{
public:
void myMgs()
{
cout<<“ProgrammingPrashn.com”;
}
};
void main()
{
Demo d; // object
Demo *ptr; // pointer to Demo class
ptr=&d; // pointer points to object ‘d’
ptr->myMgs(); // calling member function via pointer using ->
}

 

 

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.