c++列表拼接帮助
我正在尝试拼接此列表,但在调用拼接时出现错误,提示没有匹配的函数。据我所知,我的所有 #include 都是正确的。
错误来自调用 temp 的每一行。
void DeckOps::encrypt(int msize, list<int> *L){
int jokeA = 27;
int jokeB = 28;
string keystream;
list<int>::iterator a = std::find(L->begin(), L->end(), jokeA);
list<int>::iterator new_position = a;
for(int i=0; i < 1 && new_position != L->begin(); i++)
new_position--;
L->insert(new_position, 1, *a);
L->erase(b);
list<int>::iterator aa = L->begin();
int sec;
for(; aa != L->end(); aa++){
if(*aa == jokeA || *aa == jokeB)
break; //aa is at 1st inlist either 27 or 28
}
if(*aa == jokeA){
sec = jokeA;
} else {
sec = jokeB;
}
list<int>::iterator bb = std::find(L->begin(), L->end(), sec);
// everything works up to this point it seems
list<int> temp;
temp.splice(temp.end(), L, aa, bb);
temp.splice(temp.end(), L, bb);
temp.splice(temp.end(), L, begin(), aa);
L->splice(L->end(), L, aa);
L->splice(L->end(), temp);
//testing
std::copy(L->begin(), L->end(), std::ostream_iterator<int>(std::cout, " "));
}
I am trying to splice this list but I am getting an error saying no matching function when I call the splice. All my #includes are correct as far as I know.
Error is coming from every line that calls temp.
void DeckOps::encrypt(int msize, list<int> *L){
int jokeA = 27;
int jokeB = 28;
string keystream;
list<int>::iterator a = std::find(L->begin(), L->end(), jokeA);
list<int>::iterator new_position = a;
for(int i=0; i < 1 && new_position != L->begin(); i++)
new_position--;
L->insert(new_position, 1, *a);
L->erase(b);
list<int>::iterator aa = L->begin();
int sec;
for(; aa != L->end(); aa++){
if(*aa == jokeA || *aa == jokeB)
break; //aa is at 1st inlist either 27 or 28
}
if(*aa == jokeA){
sec = jokeA;
} else {
sec = jokeB;
}
list<int>::iterator bb = std::find(L->begin(), L->end(), sec);
// everything works up to this point it seems
list<int> temp;
temp.splice(temp.end(), L, aa, bb);
temp.splice(temp.end(), L, bb);
temp.splice(temp.end(), L, begin(), aa);
L->splice(L->end(), L, aa);
L->splice(L->end(), temp);
//testing
std::copy(L->begin(), L->end(), std::ostream_iterator<int>(std::cout, " "));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
L 是一个指针,您需要取消引用它。
或者您当然可以通过引用传递它,这取决于您。
L is a pointer, you need to dereference it.
Or you can of course pass it in by reference instead, up to you.
splice 函数的原型声明为:
您传递给函数的第二个参数
L
被声明为指针:这会导致无匹配函数错误,因为没有将第二个参数作为参数的 splice 函数一个指针。您必须取消引用指针
L
以匹配splice
的函数原型。The splice function has prototypes declared as:
The second parameter
L
you are passing to the functions is declared as a pointer:This results in a no matching function error because there is no splice function which takes second parameter as an pointer. You will have to dereference your pointer
L
to match the function prototype ofsplice
.