这是我正在尝试使用的提供的功能模板:
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() );
}
}
这是我的电话,我传递的函数:
void city_db::print_bst() {
postorder(&city_db::print, head);
}
void city_db::print(city_record target)
{
std::cout << target.get_code();
}
这是我得到的编译时(G++)错误:
CityDb.cpp:85:从这里实例化
BinTree.template:80:错误:必须使用 '. ' 或 '-> ' 在 'f (...)' 中调用指向成员函数的指针</p>
制作:*** [CityDb.o] 错误 1
这是参考f( node_ptr->data() );
函数模板中的行。
这是一个数据结构项目。赋值被修改了,所以我们不需要将函数传递给函数,但是我对此感兴趣已经有一段时间了,我觉得我几乎在这里。我已经用尽了 Google 和 Lab TA,所以如果 StackOverflow 有想法,他们将不胜感激。