views:

92

answers:

3

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;
}
A: 

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});
just somebody
+1  A: 

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

codaddict
+6  A: 

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;
}
aJ
Thanks, this is exactly the answer I wanted.
Blaise Roth