c++ function pointers giving runtime error when passed to push_heap -


i'm implementing djikstra's shortest path algorithm , using priority queue determine node visit next, can't use std::priority_queue because application requires heap rebuilt in place. wrote own wrapper functions std::make_heap(), std::push_heap(), , std::pop_heap() , i'm passing own comparator them, returns null pointer error during runtime. have feeling i'm either not passing function pointer correctly or function pointer isnt being initialized correctly.

here's code initializing function pointer

bool shortestdisttohere(const node& lhs, const node& rhs){     return distances[lhs.xpos][lhs.ypos] < distances[rhs.xpos][rhs.ypos]; } bool (*shortestdist)(const node& lhs, const node& rhs) = &shortestdisttohere; 

and here's function call using it

push_heap(queuevector.begin(), queuevector.end(), shortestdist); 

edit: in comments metioned there error when tried call or other on predicate. well, turns out visual studio 11 doesn't follow c++ specifications quite way (or documentation obscure) cause in reference said third argument make_heap function pointer or function object, in fact predicate needed. unless function object predicate, i've been going wrong way entire time.

the correct way call push_heap() is

push_heap(queuevector.begin(), queuevector.end(), shortestdisttohere()); 

it needs instance of functor object.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -