Saturday, October 29, 2016

Overloading Pointer To Member -> Operator :)

Tags

Program To Overload -> Pointer to Member Operator :

#include<iostream>
using namespace std;
class sample
{
public:
int n;
sample()
{
cout<<"Enter Any Value ";
cin>>n;
}
sample* operator ->()
{
return this;
}
};
main()
{
    sample a;
    sample* p=&a;
    cout<<"Accessing Using Pointer";
    cout<<"\nValue is "<<p->n;
    cout<<"\nAccessing Using Object";
    cout<<"\nValue is "<<a->n;
}
Output: