deque question


I get a compiler error and it says " no matching function for call to 'std::deque<int>::insert(std::deque<int>::reverse_iterator, int)'"
I don't quite understand what the compiler is saying. Can someone explain me what the error in a easier fashion
thanks in advance.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  #include <iostream>
#include <deque>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <vector>
#include <map>
using namespace std;


int main(){
  
    int t[]={0,1,2,3,4,5,6,7,8,9};
    vector<int>v1(t,t+10);
    deque<int>d1(v1.begin(),v1.end());
    deque<int>d2;
    d2=d1;
    d2.insert(d1.rbegin(),10);
    for(int i =0 ; i<d1.size();i++)
    {
        cout<<d1[i]<<" ";
    }
    return 0;

}
Last edited on
is it because I have forgotten to use iterator when insert?
insert() takes deque::iterator and a value. You're trying to pass deque::reverse_iterator instead.

What's worse, you're trying to pass d1's iterator into d2's member function

To append 10 to d2, you could have used:

d2.push_back(10);or
d2.insert(d2.end(), 10);or, if you must make a call to d2.rbegin(),
d2.insert(d2.rbegin().base(), 10);
Last edited on
Topic archived. No new replies allowed.