Hello...I want to make a limit for [ ] by overloading it...but it does not work...#include
#include "stdafx.h"
#include <iostream>
using namespace std;
class complex
{
friend ostream & operator<<(ostream &,const complex &);
float a,b;
public:
complex();
complex &operator[](int);
};
complex::complex()
{
a=0;
b=0;
}
ostream & operator << (ostream &output,const complex &op)
{
output<<op.a<<" + "<<op.b<<'i'<<endl;
return output;
}
complex & complex::operator[](int i)
{
if(i>9)
{
cout<<"index is out of range";
}
return *this;
}
int main()
{
complex A[10];
cout<<"A[1000] = "<<A[1000];
cin.get();
cin.get();
return 0;
}
Last edited on
Please use the code tags when submitting your code. You find them in the Format section.
Does this compile? If so, put a message in your function to see if it is being called.