Quote:Original post by Sc4Freak
In short, the code doesn't really make sense (or is very horribly broken). I suspect you've tried to type out your code from memory and messed it up - don't do this. Copy and paste the exact code you're trying to compile. We can help, but we need more information first.
Yeah, it was horribly broken and didn't make sense. I'm having a hard time understanding, but I've gotten a bit further and think this is more correct, but a few questions ...
// Is storing a function object onto a queue like below allowable? I'm getting // errors I can't even begin to understand (posted at bottom).class Scheduler{ private: typedef boost::function<void ()> event; std::priority_queue<event> pq; public: void at(time_t when, event const& what);}// Here I create 3 function objects (events) and put them on a queue.void MyApp::initTimer(){ type_t now = current_time(); for (int i = 0; i < 3; i++) { event = bind(&MyApp::print, this); scheduler->at(now + i, event); }}// But here I'm losing the time when this event is to be excuted.// How do I store the time so that I can check it in my run() and see// if time has expired so that it can be executed?void Scheduler::at(time_t when, event const& what){ pq.push(what);}// This function gets run in every frame of my game. I was hoping to just// pull off the top() of the queue, see if time expired, and if so execute the // function bound to the event. But I think my at() is messed up.scheduler->run();
And the error I get compiling ...
/bin/sh ../../../libtool --tag=CXX --mode=compile g++ -DHAVE_CONFIG_H -I. -I../../../../dnr/src/libs/events -I../../.. -I../../../../dnr/include -I/usr/local/include/OGRE -g -O2 -MT Scheduler.lo -MD -MP -MF .deps/Scheduler.Tpo -c -o Scheduler.lo ../../../../dnr/src/libs/events/Scheduler.cpp g++ -DHAVE_CONFIG_H -I. -I../../../../dnr/src/libs/events -I../../.. -I../../../../dnr/include -I/usr/local/include/OGRE -g -O2 -MT Scheduler.lo -MD -MP -MF .deps/Scheduler.Tpo -c ../../../../dnr/src/libs/events/Scheduler.cpp -fPIC -DPIC -o .libs/Scheduler.o/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4/bits/stl_function.h: In member function 'bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = boost::function<void ()(), std::allocator<void> >]':/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4/bits/stl_heap.h:279: instantiated from 'void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<boost::function<void ()(), std::allocator<void> >*, std::vector<boost::function<void ()(), std::allocator<void> >, std::allocator<boost::function<void ()(), std::allocator<void> > > > >, _Distance = long int, _Tp = boost::function<void ()(), std::allocator<void> >, _Compare = std::less<boost::function<void ()(), std::allocator<void> > >]'/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4/bits/stl_heap.h:404: instantiated from 'void std::make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<boost::function<void ()(), std::allocator<void> >*, std::vector<boost::function<void ()(), std::allocator<void> >, std::allocator<boost::function<void ()(), std::allocator<void> > > > >, _Compare = std::less<boost::function<void ()(), std::allocator<void> > >]'/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4/bits/stl_queue.h:367: instantiated from 'std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const _Compare&, const _Sequence&) [with _Tp = boost::function<void ()(), std::allocator<void> >, _Sequence = std::vector<boost::function<void ()(), std::allocator<void> >, std::allocator<boost::function<void ()(), std::allocator<void> > > >, _Compare = std::less<boost::function<void ()(), std::allocator<void> > >]'../../../../dnr/src/libs/events/Scheduler.cpp:11: instantiated from here/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4/bits/stl_function.h:227: error: no match for 'operator<' in '__x < __y'make[4]: *** [Scheduler.lo] Error 1