Question

What am I doing wrong?

#include <iostream>
#include <deque>
using namespace std;

struct mystruct {
       int number1;
       int number2;
};

int main() {
    std::deque<mystruct> mydeque;

    mydeque.number1.push_front(77);

    return 0;
}
Was it helpful?

Solution

push_front is a method of deque not the number1 of structure mystruct..

The right way is :

struct mystruct {
       int number1;
       int number2;
mystruct(int n1, int n2) : number1(n1), number2(n2){}
};

int main() {
    std::deque<mystruct> mydeque;

    mydeque.push_front(mystruct(77,88));

    return 0;
}

OTHER TIPS

The deque is of type mystruct and you are trying to push an integer.

you've declare mydeque as a container of mystructs. it's initially empty, and certainly doesn't have a public member called number1.

mydeque.push_front({77, 88});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top