如何使用Judy数组

Dar*_*Ray 4 c++ data-structures

我对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()
Run Code Online (Sandbox Code Playgroud)

这给了我错误

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*)’
Run Code Online (Sandbox Code Playgroud)

请有人帮我弄清楚我在做什么错误..谢谢

Omn*_*ous 5

根据文档,您可以反转_PValueJudyArray参数.让你的通话看起来像这样:

JSLI( _PValue, JudyArray, (uint8_t *) String);  
Run Code Online (Sandbox Code Playgroud)

另外,不要将其编译为C++代码.到目前为止,您的测试不使用C++功能.我打赌它会编译为C代码.看起来JudyArray依赖于C将在void *其他指针类型之间进行某些类型的隐式转换这一事实.

如果是这种情况,我不知道该怎么做.您收到的错误消息告诉我这JSLI是一个宏.为了修复您在此答案的评论中的错误消息,您必须到达宏内部并添加类型转换.

在C中允许这种类型的隐式转换,因为否则使用malloc总是需要丑陋的转换.C++故意不允许它们,因为语义new要求malloc将正确类型的结果转换为不重要的要求.

我不认为这个库可以在C++中有效地使用.