Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default constructor cannot be referenced -- It's a deleted function in VS

I try to compile the code from https://github.com/zcbenz/BPlusTree in Visual Studio 2015 Community. The code can be compiled in gcc, but in VS, I got

the default constructor of "bpt::internal_node_t" cannot be referenced -- it is a deleted function

the structure goes like this:

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];
}; 

references can be seen everywhere in bpt.cc, like this

internal_node_t parent;

I don't really get what the message means. How to make the code compiled in VS?

some type definition update:

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 */
};

I use off_t in <sys\types.h> and a marco #define bzero(ptr, size) memset(ptr, 0, size) for bzero

I also write another program like this:

#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;
}

That works in VS2015.

like image 439
zl2003cn Avatar asked Oct 30 '22 19:10

zl2003cn


1 Answers

I find it unlikely that a codebase that relies on POSIX types will compile in a compiler that targets Windows. Maybe you should try something like Cygwin.

For example, both off_t and key_t come from <sys/types.h>. The author didn't even bother including this header, giving a false sense of portability.

NOTE: VS2015 does have off_t. It seems the actual issue is System V IPC (<sys/ipc.h>, the actual header that cares about key_t) which is linux specific.

like image 139
user123456789 Avatar answered Nov 15 '22 05:11

user123456789