Hi everyone,
I just started doing C++ coming from a java background. I'm writing a discrete event simulator at the moment and need to put 'job' objects into a priority queue and sort them by their next job time- i.e. shortest job time first. I first tried doing the following: defining a container
priority_queue<Job,vector<Job*>,less<vector<Job*>::value_type> > event_list;
I got into a lot of trouble doing this because when I debugged the code I ended up with every element of the priority queue pointing to the same memory location. I am too inexperienced in c++ to fix this, so I tried:
priority_queue<Job,vector<Job>,less<vector<Job>::value_type> > event_list;
i.e. a priority queue of objects, not pointers. When I did this the compiler really didn't like it and brought up line 238 of vector.tcc and an error message:
"238 C:\Dev-Cpp\include\c++\3.4.2\bits\vector.tcc instantiated from `void std::vector<_Tp, _Alloc>::_M_insert_aux(__gnu_cxx::__normal_iterator<typename _Alloc::pointer, std::vector<_Tp, _Alloc> >, const _Tp&) [with _Tp = Source, _Alloc = std::allocator<Source>]' "
My question is: what should I do normally? Use pointers to objects in the container or objects? What does this error message mean?
Thanks, I'm just a novice c++ programmer so I'm sorry if this is dumb.