#include<iostream.h>
class M
{
int x;
int y;
public:
void set_xy(int a,int b)
{
x=a;
y=b;
}
friend int sum(M m);
};
int sum(M m)
{
int M ::* px=&M :: x;
int M ::* py=&M :: y;
M *pm=&m;
int s=m.*px + pm->*py;
return s;
}
main()
{
M n;
void (M :: *pf)(int,int)=&M :: set_xy;
(n.*pf)(10,20);
cout<<"Sum="<<sum(n)<<"\n";
M *op=&n;
(op->*pf)(30,40);
cout<<"Sum="<<sum(n)<<"\n";
return(0);
}
Output:
Sum=30
Sum=70
Not Satisfied ? Just search & get the result
Related posts:
- C++ program – illustrate the static member function
- Sample – Program to find the sum of each row & column of a matrix of size n x m and if matrix is square, find the sum of the diagonals also..
- Sample – Program to find the sum of either of the diagonals of a 4 x 4 matrix.
- C++ program – illustrate a Single Inheritance
- C program to accept two matrices and find the sum and difference of the matrices
