我正在使用哈希表(Google Inc.的源代码)来存储一些定义为:
typedef Object *(Executor::*expression_delegate_t)( vframe_t *, Node * );
显然,“执行者”是类。
向哈希表中插入一些值的函数原型是:
hash_item_t *ht_insert( hash_table_t *ht, ulong key, ulong data );
所以基本上我要做的是插入双精度转换方法指针:
ht_insert( table, ASSIGN, reinterpret_cast<ulong>( (void *)&Executor::onAssign ) );
在哪里?
table
定义为“A”
hash_table_t *
'在执行器类的声明中,
ASSIGN
是无符号长值,并且'
onAssign
'是我必须映射的方法。
现在,
Executor::onAssign
存储为一个无符号长值,我认为它在内存中的地址,我需要将ulong转换回一个方法指针。但是这个代码:
hash_item_t* item = ht_find( table, ASSIGN );
expression_delegate_t delegate = reinterpret_cast < expression_delegate_t > (item->data);
给出以下编译错误:
src/executor.cpp:45: error: invalid cast from type âulongâ to type âObject* (Executor::*)(vframe_t*, Node*)â
我在x86 GNU/Linux机器上使用GCC4.4.3。
有什么暗示吗?