This is the provided function template I'm trying to use:
template <class Process, class BTNode>
void postorder(Process f, BTNode* node_ptr)
{
if (node_ptr != 0)
{
postorder( f, node_ptr->left() );
postorder( f, node_ptr->right() );
f( node_ptr->data() );
}
}
This is my call, and the function I'm passing:
void city_db::print_bst() {
postorder(&city_db::print, head);
}
void city_db::print(city_record target)
{
std::cout << target.get_code();
}
This is the compile time (G++) error I get:
CityDb.cpp:85: instantiated from here
BinTree.template:80: error: must use ‘.’ or ‘->’ to call pointer-to-member function in ‘f (...)’
make: *** [CityDb.o] Error 1
This is in reference to the line f( node_ptr->data() );
in the function template.
This is for a Data Structures project. The assignment was modified so we don't need to pass a function to a function, but I've been interested in this for quite some time, and I feel like I almost have it here. I've exhausted Google and Lab TA's, so if StackOverflow has ideas, they would be greatly appreciated.