I'm new to C++ (I did C before but never C++) I believe I have syntax problem.
I want to sort some orders by price level into a list. So my list has positions with inside:
- the price level
- another
std::list
with all orders at that price. (Orders)
An Order
is a struct with:
userid
quantity
So I ended with :
#include<iostream>
#include<list>
using namespace std;
typedef struct Order {
int userid;
int qty;
} Order;
typedef struct Bid {
int price;
list<Order> Orders;
} Bid;
typedef list<Bid> bids;
int main(void)
{
bids list;
Order order_to_insert;
list.begin();
list.front().price = 13000;
order_to_insert.userid = 3;
order_to_insert.qty = 20;
list.front().Orders.begin();
list.front().Orders.front().userid =3;
list.front().Orders.front().qty = 20;
// list.front().Orders.front() = order_to_insert; // compiles even if i uncomment this.
cout << "Liste : " << list.front().price << endl;
cout << list.front().Orders.front().qty << endl;
return 0;
}
The most intuitive way initially was to use the commented line, it compiles but gives seg fault.
I commented to assign values to fields directly and it seg fault also.
What is the proper way to do that?