错误:无法取消引用值初始化的向量迭代器
当我尝试引用迭代器时
/*
* e.g. ["1","2","3"] will produce => [ ["1","2","3"], ["2","3","1"], ["3","1","2"],]
*/
vector<vector<string>> getRotation(vector<string> in) {
size_t num_rotation = in.size() - 1;
vector<string> variantion(in);
vector<vector<string>> result{ in };
for (size_t i = 0; i < num_rotation; i++)
{
vector<string>::iterator temp = variantion.begin();
string tempValue = *temp; // Error: can't dereference value-initialized vector iterator
// variantion remove the first element ,and append to the end
variantion.erase(temp);
variantion.push_back(tempValue);
result.push_back(variantion);
}
return result;
}
答案 0 :(得分:0)
它最终使我的参数的大小为0,因此此代码为我返回了一个空迭代器
vector<string>::iterator temp = variantion.begin();
我认为这就是它引发错误的原因。