我正在尝试在 c++ 实现中使用 ac 库,并且我经常遇到与“候选函数不可行”有关的错误,并且似乎认为库中的函数无法使用我的代码中提供的参数. 问题是,我的代码实际上是一个旧的实现(在 c 中),在 c 中编译时工作得非常好。有没有办法让它编译为我的 c++ 环境的一部分?
这是我得到的错误:
testbed/des-lsr_routinglogic.cpp:20:27: error: no matching function for call to 'dessert_periodic_add'
periodic_refresh_nh = dessert_periodic_add(refresh_list, NULL, NULL, &refresh_neighbor_t);
^~~~~~~~~~~~~~~~~~~~
/usr/local/include/dessert.h:880:21: note: candidate function not viable: no known conversion from 'dessert_per_result_t ()' to 'dessert_periodiccallback_t *' (aka 'dessert_per_result_t (*)(void *, struct
timeval *, struct timeval *)') for 1st argument
dessert_periodic_t* dessert_periodic_add(dessert_periodiccallback_t* c, void* data, const struct timeval* scheduled, const struct timeval* interval);
^
从这行代码代码:
periodic_refresh_nh = dessert_periodic_add(refresh_list, NULL, NULL, &refresh_neighbor_t);
使用图书馆的这段摘录:
dessert_periodic_t* dessert_periodic_add(dessert_periodiccallback_t* c, void* data, const struct timeval* scheduled, const struct timeval* interval);
dessert_periodic_t* dessert_periodic_add_delayed(dessert_periodiccallback_t* c, void* data, int delay);
int dessert_periodic_del(dessert_periodic_t* p);
void dessert_register_ptr_name(void* ptr, const char* name);
const char* dessert_ptr2name(void* ptr);
我认为编译器输出对于任何有结合 c/c++ 经验的人来说应该是不言而喻的,但对我来说它看起来像胡言乱语 D:
编辑
谢谢,有人向我指出我遗漏了一些重要的定义;refresh_list的定义:
dessert_per_result_t refresh_list(void *data, struct timeval *scheduled, struct timeval *interval) {
pthread_rwlock_wrlock(&pp_rwlock);
node_neighbors_t *neighbor = dir_neighbors_head;
while (neighbor) {
if (neighbor->entry_age-- == 0) {
node_neighbors_t* el_to_delete = neighbor;
HASH_DEL(dir_neighbors_head, el_to_delete);
free(el_to_delete);
} else {
neighbor->weight = 1;
}
neighbor = neighbor->hh.next;
}
pthread_rwlock_unlock(&pp_rwlock);
return 0; }
甜点_per_result_t的定义:
typedef enum _dessert_periodic_results { DESSERT_PER_KEEP = 0, DESSERT_PER_UNREGISTER = 1 } dessert_per_result_t;
sweet_periodiccallback_t 的定义很奇怪;我会尝试发布它。