Overload () operator for two values : overload bracket operator « Operator Overloading « C++ Tutorial






#include<iostream.h>
class Sample
{
  int A[10][10];
public:
       int &operator()(int,int);
};
int &Sample::operator()(int x,int y)
{
  cout << "()";
  return A[x][y];
}

int main()
{
  Sample a;
  int i,j;
  for(i=0;i<10;i++){
         for(j=0;j<10;j++)
                 a(i,j)=i+j;
         for(i=0;i<10;i++)
                 cout<<a(i,1)<<" ";
  }
         cout<<endl;
}
10 10








10.9.overload bracket operator
10.9.1.Overload ( ) for Point
10.9.2.overloading ( ) for the loc class
10.9.3.The overloaded operator[ ]( ) function returns the value of the array as indexed by the value of its parameter.
10.9.4.design the operator[ ]( ) function in such a way that the [ ] can be used on both the left and right sides of an assignment statement.
10.9.5.Add a range check to for overloaded [] operator
10.9.6.Overload () operator for two values