c++列表拼接帮助

发布于 2024-11-09 06:59:09 字数 1512 浏览 6 评论 0原文

我正在尝试拼接此列表,但在调用拼接时出现错误,提示没有匹配的函数。据我所知,我的所有 #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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清醇 2024-11-16 06:59:09

L 是一个指针,您需要取消引用它。

temp.splice(temp.end(), *L, aa, bb);

或者您当然可以通过引用传递它,这取决于您。

L is a pointer, you need to dereference it.

temp.splice(temp.end(), *L, aa, bb);

Or you can of course pass it in by reference instead, up to you.

擦肩而过的背影 2024-11-16 06:59:09

splice 函数的原型声明为:

void splice ( iterator position, list<T,Allocator>& x );
void splice ( iterator position, list<T,Allocator>& x, iterator i );
void splice ( iterator position, list<T,Allocator>& x, iterator first, iterator last );

您传递给函数的第二个参数 L 被声明为指针:

list<int> *L

这会导致无匹配函数错误,因为没有将第二个参数作为参数的 splice 函数一个指针。您必须取消引用指针L以匹配splice的函数原型。

temp.splice(temp.end(), *L, aa, bb);
temp.splice(temp.end(), *L, bb);
temp.splice(temp.end(), *L, begin(), aa);

The splice function has prototypes declared as:

void splice ( iterator position, list<T,Allocator>& x );
void splice ( iterator position, list<T,Allocator>& x, iterator i );
void splice ( iterator position, list<T,Allocator>& x, iterator first, iterator last );

The second parameter L you are passing to the functions is declared as a pointer:

list<int> *L

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 of splice.

temp.splice(temp.end(), *L, aa, bb);
temp.splice(temp.end(), *L, bb);
temp.splice(temp.end(), *L, begin(), aa);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文