无法引用默认构造函数 -- 这是 VS 中的已删除函数

zl2*_*3cn 5 c++ visual-studio

我尝试从Visual Studio 2015 社区中的https://github.com/zcbenz/BPlusTree编译代码。代码可以在gcc中编译,但是在VS中,我得到了

“bpt::internal_node_t”的默认构造函数不能被引用——它是一个被删除的函数

结构是这样的:

struct internal_node_t {
    typedef index_t * child_t;

    off_t parent; /* parent node offset */
    off_t next;
    off_t prev;
    size_t n; /* how many children */
    index_t children[BP_ORDER];
}; 
Run Code Online (Sandbox Code Playgroud)

中随处可见的引用bpt.cc,像这样

internal_node_t parent;
Run Code Online (Sandbox Code Playgroud)

我真的不明白这个消息是什么意思。如何使代码在VS中编译?

一些类型定义更新:

struct key_t {
    char k[16];

    key_t(const char *str = "")
    {
        bzero(k, sizeof(k));
        strcpy_s(k, str);
    }
};
typedef unsigned int     size_t;

struct index_t {
    key_t key;
    off_t child; /* child's offset */
};
Run Code Online (Sandbox Code Playgroud)

我使用off_tin<sys\types.h>和 marco #define bzero(ptr, size) memset(ptr, 0, size)forbzero

我还写了另一个这样的程序:

#include <sys/types.h>
#include <string.h>

#define bzero(ptr, size) memset(ptr, 0, size)

struct key_t {
    char k[16];

    key_t(const char *str = "")
    {
        bzero(k, sizeof(k));
        strcpy_s(k, str);
    }
};
struct index_t {
    key_t key;
    off_t child; /* child's offset */
};



struct internal_node_t {
    typedef index_t * child_t;

    off_t parent; /* parent node offset */
    off_t next;
    off_t prev;
    size_t n; /* how many children */
    index_t children[20];
};

int main() {
    internal_node_t t;
}
Run Code Online (Sandbox Code Playgroud)

这在 VS2015 中有效。

use*_*789 2

我发现依赖 POSIX 类型的代码库不太可能在面向 Windows 的编译器中进行编译。也许你应该尝试像 Cygwin 这样的东西。

例如, 和off_tkey_t来自<sys/types.h>。作者甚至没有费心包含这个标头,给人一种可移植性的错误感觉。

注意:VS2015确实有off_t. 看起来实际的问题是 System V IPC(<sys/ipc.h>,关心的实际标头key_t),这是 Linux 特定的。