c++ - C程序到C++ B+树

标签 c++ c debugging

我通常用 C 编写代码,但在尝试学习 C++ 时,我一直在实现 B+ 树,但遇到了一些错误。这是我的功能

void print_leaves(node *root)
{
    int i;
    node *c = root;
    if (root == NULL) {
        cout << "Empty tree" << endl;
        return;
    }
    while (!c->is_leaf)
    {
        c = c->pointers[0];
    }
    while (true)
    {
        for (i = 0; i < c->num_keys; i++)
        {
            printf("%d ", c->keys[i]);
        }

        if (c->pointers[order - 1] != NULL)
        {
            cout << " | ";
            c = c->pointers[order - 1];
        }
        else
            break;
    }
    cout << endl;
}

这是我得到的错误:

C:\Users\Main\Desktop\test.cpp||In function 'void print_leaves(node*)':|
C:\Users\Main\Desktop\test.cpp|95|error: invalid conversion from 'void*' to 'node*' [-fpermissive]|
C:\Users\Main\Desktop\test.cpp|107|error: invalid conversion from 'void*' to 'node*' [-fpermissive]|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

我在网上看过,看到使用 malloc 函数时会发生这种情况,但我目前没有使用它。塔克斯

最佳答案

在 C++ 中,与 C 不同,void* 不会自动转换为其他指针类型。

您可能不应该在此程序中使用 void*node 应该指向其他 node,而不是未知的内存块,因此最好为这些指针提供适当的类型。

关于c++ - C程序到C++ B+树,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27339366/

相关文章:

C++ 堆损坏

c - 打印 uint8_t

c++ - 将 SOIL.lib 与 GCC 一起使用 - 添加符号时出错 : File format not recognised

c - 当询问用户名时getenv返回null?

c - 我的函数中的格式代码

debugging - 如何记录和跟踪 NodeJS 事件和事件处理程序调用?

c++ - 从二进制文件输入字符串时出现未处理的异常 | Visual Studio

c++ - 为 Windows 编译静态 TagLib 1.6.3 库

c++ - 自动修复 C 中缺少的括号

c - 对话框无法第二次打开。 GTK+、Glade 和 C