我希望后者使用前者。我怎么能在 C++ 中做到这一点?如果不可能,为什么我不能做*this = regMatrix
任务?
RegMatrix::RegMatrix(int numRow,int numCol)
{
int i;
for(i=0;i<numRow;i++)
{
_matrix.push_back(vector<double>(numCol,0));
}
}
RegMatrix::RegMatrix(const SparseMatrix &sparseMatrix)
{
RegMatrix regMatrix(sparseMatrix.getNumRow(),sparseMatrix.getNumCol());
vector<Node> matrix = sparseMatrix.getMatrix();
cout << "size: " << matrix.size() << endl;
for(std::vector<Node>::const_iterator it = matrix.begin(); it != matrix.end(); ++it )
{
cout << "Position: [" << (*it).i << ", " << (*it).j << "] Value:" << (*it).value << endl;
regMatrix._matrix[(*it).i][(*it).j] = (*it).value;
}
*this = regMatrix;
}