How to overload C++ operator [][] in class Matrix if want to return vector of vectors Data?
class Matrix
{
public:
Matrix(int rows, int columns);
// double operator[][](int RowIndex,int ColIndex);
class Proxy {
public:
Proxy(int pCol){
pData.resize(pCol);
}
double& operator[](int index) {
return pData[index];
}
private:
std::vector<double> pData;
};
Proxy operator[](int index) {
return Proxy(Data[index]);
}
protected:
int Rows;
int Columns;
std::vector<std::vector<double>> Data;
};
error: no matching function for call to ‘Matrix::Proxy::Proxy(__gnu_cxx::__alloc_traits > >::value_type&)’ return Proxy(Data[index]);
so i need smth like this:
double& operator[][](int IndexRow,int IndexCol){
return Data[IndexRow][IndexCol];
}