Pav*_*yan 0 c++ struct stdvector
这是代码:
typedef struct Triplet
{
double value;
int row;
int column;
};
class Matrix
{
public:
//Some methods
double specialMethod(/*params*/);
private:
std::vector<Triplet> elements;
int nRows;
int nColumns;
};
Run Code Online (Sandbox Code Playgroud)
在specialMethod被调用之后,Matrix.element中的值被破坏.但除了像这样迭代之外,没有任何事情可以做到:
std::vector<Triplet>::iterator it;
std::vector<Pair> buff;
for (it = this->elements.begin(); it != this->elements.end(); ++it)
{
if (it->column = n)
{
Pair p;
p.key = it->row;
p.value = it->value;
buff.push_back(p);
}
}
Run Code Online (Sandbox Code Playgroud)
不知道从哪里开始寻找错误.
if (it->column = n)
Run Code Online (Sandbox Code Playgroud)
应该:
if (it->column == n)
Run Code Online (Sandbox Code Playgroud)
你正在做比较而不是分配.