我想在我的类中覆盖数组索引运算符。这是我想要做的,但没有成功。
class Complex{
Complex const& operator[](unsigned int) const; // Read-only access
Complex& operator[](unsigned int); // Read/Write access:
};
const Complex& Complex::operator [](unsigned int unsignedInt) const {
const Complex* temp = this+i;
return *temp;
}
Complex& Complex::operator [](unsigned int unsignedInt) {
Complex* temp = this+i;
return *temp;
}
编辑:我想做类似的事情:
Complex **c = new Complex[5]; //Create 2D array
c[2] = new Complex(); //Initialize
cout<<*c[2]; //print by overloading <<