Write a program to call member functions of class in the main function using pointer to object and pointer to member function.
CODING:
#include<iostream.h>
#include<conio.h>
class a{
int a;
public:
int b;
void setdata()
{
a=4,
b=9;
};
void display()
{
cout<<"A:"<<a<<endl<<"B:"<<b;
}
};
void main()
{
a obj;
clrscr();
obj.setdata();
obj.display();
obj.b=8;
cout<<endl;
obj.display();
a *p;
p=&obj;
p->b=7;
cout<<endl;
p->display();
getch();
}
CODING:
#include<iostream.h>
#include<conio.h>
class a{
int a;
public:
int b;
void setdata()
{
a=4,
b=9;
};
void display()
{
cout<<"A:"<<a<<endl<<"B:"<<b;
}
};
void main()
{
a obj;
clrscr();
obj.setdata();
obj.display();
obj.b=8;
cout<<endl;
obj.display();
a *p;
p=&obj;
p->b=7;
cout<<endl;
p->display();
getch();
}
Comments
Post a Comment