I am writing a small user interface for my program. I have an onMouseMotion() method, which I can name in one of two ways (see Code); if I call it via std::function , the != operator in loop stop mode throws an exception at runtime vector iterators incompatible . Why?
class Widget : public EventHandler { protected: std::vector<Widget *> children_; std::function<bool(Event &)> func_; private: bool onMouseMotion(Event &event); }; Widget::Widget() { func_ = std::bind(&Widget::onMouseMotion, this, std::placeholders::_1); } bool Widget::processEvent(Event &event) { if (event.getType() == ui::EventType::MouseMotionEvent) { onMouseMotion(event);
Updates :
- The program is single-threaded.
- an exception occurs when you enter a
for loop, zero iterations occur. - compilation with MSVC.
- same exception with empty
for loop. - rewritten examples to illustrate the
std::function problem.
c ++ iterator vector visual-c ++ std-function
Dan nestor
source share