我有一個結構如下:不平凡的指定初始化不支持
struct app_data
{
int port;
int ib_port;
unsigned size;
int tx_depth;
int sockfd;
char *servername;
struct ib_connection local_connection;
struct ib_connection *remote_connection;
struct ibv_device *ib_dev;
};
當我嘗試從而將其初始化:
struct app_data data =
{
.port = 18515,
.ib_port = 1,
.size = 65536,
.tx_depth = 100,
.sockfd = -1,
.servername = NULL,
.remote_connection = NULL,
.ib_dev = NULL
};
我得到這個錯誤:
sorry, unimplemented: non-trivial designated initializers not supported
我認爲它想要按照聲明的順序進行初始化,並且缺少local_connection
。我不需要初始化它,並將其設置爲NULL不起作用。
如果我將其更改爲這對G ++,仍然得到同樣的錯誤:
struct app_data data =
{
port : 18515,
ib_port : 1,
size : 65536,
tx_depth : 100,
sockfd : -1,
servername : NULL,
remote_connection : NULL,
ib_dev : NULL
};
我想你正在使用g ++來編譯這段代碼。如果是,請刪除「。」即.port成爲端口,.ib_port變爲ib_port。它應該在那之後編譯。 – Anon
我使用g ++ 4.9.2(啓用了C++ 11),但刪除了。不起作用? 「端口未在此範圍內聲明」 – Ivan
哦。忘了提及,請使用「:」而不是「=」例如端口:18515,併爲其他變量也做。 – Anon