我对 Judy Arrays 很感兴趣并尝试使用它。但是我无法使用它做任何有用的事情。每次它给我转换错误时。示例 C++ 代码和下面给出的错误。
#include "Judy.h"
#include <iostream>
using namespace std;
int main()
{
int Rc_int; // return code - integer
Word_t Rc_word; // return code - unsigned word
Word_t Index = 12, Index1 = 34, Index2 = 55, Nth;
Word_t PValue; // pointer to return value
//Pvoid_t PJLArray = NULL; // initialize JudyL array
Pvoid_t JudyArray = NULL;
char String[100];
PWord_t _PValue;
JSLI( JudyArray, _PValue, (uint8_t *) String);
return(0);
} // main()
这给了我错误
m.cpp: In function ‘int main()’:
m.cpp:19: error: invalid conversion from ‘long unsigned int**’ to ‘void**’
m.cpp:19: error: initializing argument 1 of ‘void** JudySLIns(void**, const uint8_t*, J_UDY_ERROR_STRUCT*)’
请任何人帮助我找出我正在做的错误是什么.. 谢谢
最佳答案
根据 the documentation ,您将 _PValue
和 JudyArray
参数颠倒了。让你的电话看起来像这样:
JSLI( _PValue, JudyArray, (uint8_t *) String);
此外,尽量不要将其编译为 C++ 代码。到目前为止,您的测试没有使用任何 C++ 功能。我敢打赌它会编译为 C 代码。看起来 JudyArray 依赖于 C 将在 void *
和其他指针类型之间进行某些类型的隐式转换这一事实。
如果是这种情况,我不知道该怎么办。您收到的错误消息告诉我 JSLI
是一个宏。为了修复您在此答案的评论中的错误消息,您必须进入宏内部并添加类型转换。
C 中允许这些类型的隐式转换,否则使用 malloc
将总是需要丑陋的转换。 C++ 故意不允许它们,因为 new
的语义要求将 malloc
的结果强制转换为不重要的正确类型。
出于这个原因,我认为这个库不能在 C++ 中有效使用。
关于c++ - 如何使用 Judy 阵列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6420458/