如果想要返回向量数据的向量,如何在类Matrix中重载C ++ operator [] []?
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;
};
错误:没有匹配函数来调用'Matrix :: Proxy :: Proxy(__ gnu_cxx :: __ alloc_traits&gt;&gt; :: value_type&amp;)' return Proxy(Data [index]);
所以我需要这样的smth:
double& operator[][](int IndexRow,int IndexCol){
return Data[IndexRow][IndexCol];
}