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;
}
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;
}
you've declare mydeque
as a container of mystruct
s. it's initially empty, and certainly doesn't have a public member called number1
.
mydeque.push_front({77, 88});
The deque is of type mystruct
and you are trying to push an integer
.
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;
}