gpt4 book ai didi

c++如何使用另一个ctor的ctor?

转载 作者:行者123 更新时间:2023-11-28 07:48:29 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Calling another constructor when constructing an object with const members

我希望后者使用前者。我怎么能在 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;
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com