【发布时间】:2021-01-12 12:54:25
【问题描述】:
我已将值分配给结构中的字段。这导致了多个错误。
typedef struct t_queue {
int head = 0;
int tail = 0;
int maxSize = 0;
int size = 0;
SOCKET* queue = NULL;
}Queue;
typedef struct t_threadData {
int topicID;
bool isEngineActive = FALSE;
bool isServerActive = TRUE;
int numberOfConnectedSubs = 0;
Queue* queue;
HANDLE PublisherReady;
HANDLE ThreadReady;
HANDLE BarrierOK;
CRITICAL_SECTION Critical_Section;
int NumberOfThreadsWaiting = 0;
SOCKET sockets[NUMBER_OF_SUBSCRIBERS];
}ThreadData;
错误是:
-
E0065 需要一个 ';'
-
E0020 标识符“bool”未定义
我正在使用 Visual Studio Enterprise 2017 在 Windows 10 上使用 C 语言工作。
提前感谢您的帮助。
【问题讨论】:
-
Please do not post images of code because they are hard to use. 代码应作为文本直接发布在您的问题中。
-
C 中的结构不能这样使用。如果您想这样做,请使用 C++11 或更高版本。
-
这是一个结构体的定义,它只是描述结构体中的字段、它们的类型和顺序,你不能给它们赋值。
-
我明白了。谢谢
-
要在 C 中使用
bool,请添加#include <stdbool.h>。