开发者

c++ list splicing help

开发者 https://www.devze.com 2023-03-07 18:36 出处:网络
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.

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++)
        n开发者_高级运维ew_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, " "));
}


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.


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消