从C到C++的结构用法代码 我将使用C结构数据到C++类的代码有问题。 声明此结构线程并初始化由3个元素组成的数组 static struct thread { const char *const filename; size_t buf_size; ssize_t (*in)(struct thread *, void *, size_t); const char *const in_name; ssize_t (*out)(struct thread *, const void *, size_t); const char *const out_name; int fd; pthread_t id; void *buf; ssize_t status; } threads[] = { { "ep0", 4 * sizeof(struct usb_functionfs_event), read_wrap, NULL, ep0_consume, "<consume>", 0, 0, NULL, 0 }, { "ep1", 8 * 1024, fill_in_buf, "<in>", write_wrap, NULL, 0, 0, NULL, 0 }, { "ep2", 8 * 1024, read_wrap, NULL, empty_out_buf, "<out>", 0, 0, NULL, 0 }, };

从C到C++的结构用法代码 我将使用C结构数据到C++类的代码有问题。 声明此结构线程并初始化由3个元素组成的数组 static struct thread { const char *const filename; size_t buf_size; ssize_t (*in)(struct thread *, void *, size_t); const char *const in_name; ssize_t (*out)(struct thread *, const void *, size_t); const char *const out_name; int fd; pthread_t id; void *buf; ssize_t status; } threads[] = { { "ep0", 4 * sizeof(struct usb_functionfs_event), read_wrap, NULL, ep0_consume, "<consume>", 0, 0, NULL, 0 }, { "ep1", 8 * 1024, fill_in_buf, "<in>", write_wrap, NULL, 0, 0, NULL, 0 }, { "ep2", 8 * 1024, read_wrap, NULL, empty_out_buf, "<out>", 0, 0, NULL, 0 }, };,c++,struct,C++,Struct,作为我的类的私有成员,我创建了这个结构的3个元素的数组: 编译时会出现以下错误: In constructor "MyClass::MyClass(MyClass::UsbDescription*, void*)": /MyClass.cpp:76:65: error: uninitialized const member in "struct stThread" In file included from RDEmbeddedTools/FunctionFS.cpp:2:0: MyClass

作为我的类的私有成员,我创建了这个结构的3个元素的数组:

编译时会出现以下错误:

 In constructor "MyClass::MyClass(MyClass::UsbDescription*, void*)":
/MyClass.cpp:76:65: error: uninitialized const member in "struct stThread"
In file included from RDEmbeddedTools/FunctionFS.cpp:2:0:
MyClass.hpp:78:20: note: "stThread::filename" should be initialized
MyClass.cpp:76:65: error: uninitialized const member in "struct stThread"
我的代码怎么了? 另外,如何为构造函数中数组线程的3个元素赋值? 还有比这更舒适的方式吗:

threads[0].filename = "foo";
threads[0].buf_size = 1024;
...

我认为错误信息很清楚:错误:struct stthread中未初始化的const成员谢谢,我完全忽略了const。
 In constructor "MyClass::MyClass(MyClass::UsbDescription*, void*)":
/MyClass.cpp:76:65: error: uninitialized const member in "struct stThread"
In file included from RDEmbeddedTools/FunctionFS.cpp:2:0:
MyClass.hpp:78:20: note: "stThread::filename" should be initialized
MyClass.cpp:76:65: error: uninitialized const member in "struct stThread"
threads[0].filename = "foo";
threads[0].buf_size = 1024;
...