c++ - Calling pointer-to-member function in call for a function passed to a template function -


This is a given function template that I'm trying to use:

  template & lt; Class process, class btnode & gt; Zero Post Order (Process F, BTnode * Node_PTR) {if (node_ptr! = 0) {postorder (f, node_ptr-> left ()); Post Order (F, Node_PTR- & gt; Correct ()); F (node_ptr-> data ()); }}   

This is my call, and the function that I am passing:

  zero city_db :: print_bst () {Posters (and city_dib :: print, head); } Zero city_db :: print (city_record target) {std :: cout & lt; & Lt; Target.get_code (); }  

This is the compilation time (G ++) error I receive:

CityDb.cpp: 85: From here immediately

BinTree.template: 80: Error: 'F (...)' to call the Pointer-to-Member function. ' 'or' -> 'should be used

: *** [Citibob] error 1

this line < Regarding the code> f (node_ptr-> data ()); in the function template.

This data structure is for project. The assignment was modified so we do not need to give the function to the function, but I'm interested in it for some time, and I think I keep it around here. I have terminated Google and Lab TA, so if the views of the stack are overflow, they would be very much appreciated.

Your problem is that the postorder accepts a function object that should be called in this way:

  f (arg);  

You are passing in an indicator on the member function. You should first call mem_fun from point to point member to create function object:

  std :: mem_fun (& city_db :: print)  

The return function object takes two arguments: a city_db (this indicator contains) and the object to print indicator. You can tie it to bind1st first, like this:

  std :: bind1st (std :: mem_fun (& city_db :: print), this)  

And now you should be able to call the post order on it:

  Post Order (std :: bind1st (std :: mem_fun (& city_db :: print), head) ;  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -