Overload [] operator
#include<iostream.h>class backet
{
private: int a[3];
public: backet()
{
}
backet(int i,int j,int k)
{
a[0]=i;
a[1]=j;
a[2]=k;
}
int operator [](int i)
{
return a[i];
}
};
void main()
{
backet ob(1,2,3);
for(int i=0;i<3;i++)
cout<<"\t"<<ob[i];
}
Output:
Overload ->operator
#include<iostream.h>class arrow
{
public:
int i;
arrow *operator->()
{
return this;
}
};
void main()
{
arrow ob;
ob->i=10;
cout<<"\t"<<ob.i<<"\t"<<ob->i;
}
Output:
No comments:
Post a Comment