oop - C++ Erase-remove idiom with object -


edit: @holt helped me, solution pass instance of engine if hascollided non-static:

std::bind(&engine::hascollided, this, ball, _1); 

i have function returns true or false whether brick hit ball.

i want erase brick hit vector. managed idiom working simple vector of numbers , bool function, strange errors when try same vector of objects.

private members:

ball ball; std::vector<brick> bricks; 

collision check:

bool engine::hascollided(ball& object1, brick& object2) {     //do checks     return 1; } 

my attempt:

using namespace std::placeholders;  auto f = std::bind(hascollided, ball, _1); bricks.erase(std::remove_if(bricks.begin(), bricks.end(), f), bricks.end()); 

error happens in predefined_ops.h right here:

template<typename _iterator>     bool     operator()(_iterator __it)     { return bool(_m_pred(*__it)); }     }; 

and compiler spits out 92 errors. please me fix that

example error:

required '_forwarditerator std::__remove_if(_forwarditerator, _forwarditerator, _predicate) [with _forwarditerator = __gnu_cxx::__normal_iterator<game::brick*, std::vector<game::brick> >; _predicate = __gnu_cxx::__ops::_iter_pred<std::_bind<std::_mem_fn<bool (game::engine::*)(game::ball&, game::brick&)>(game::ball, std::_placeholder<1>)> >]'

since hascollided not static function, need pass instance of engine std::bind.

assuming doing erase/remove inside method of engine, can following:

auto f = std::bind(&engine::hascollided, this, ball, _1); //                                       ^^^^ 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -