【问题标题】:c++, syntax error : missing ';' before identifier 'N0'c++,语法错误:缺少';'在标识符“N0”之前
【发布时间】:2015-01-05 16:55:06
【问题描述】:

我在 Windows 上编译代码时遇到问题。

在基于 Unix 的系统上一切正常,但是当我在 Windows 上编译它时(目前使用 Visual Studio 2010 Express),我收到以下错误:

错误 253 错误 C2146:语法错误:缺少 ';'在标识符“N0”之前 C:\ghost++\ghost\ohconnect.h 45

错误 254 错误 C4430:缺少类型说明符 - 假定为 int。注意:C++ 不支持 default-int C:\ghost++\ghost\ohconnect.h 45

错误 255 错误 C4430:缺少类型说明符 - 假定为 int。注意:C++ 不支持 default-int C:\ghost++\ghost\ohconnect.h 45

错误 256 错误 C2146:语法错误:缺少 ';'在标识符“N”之前 C:\ghost++\ghost\ohconnect.h 46

错误 257 错误 C4430:缺少类型说明符 - 假定为 int。注意:C++ 不支持 default-int C:\ghost++\ghost\ohconnect.h 46

等等。 我认为这都与我的头文件有关,该类本身是用来连接到 websockets 的:

#ifndef OHConnect_H
#define OHConnect_H

//
// OHCONNECT
//

class CTCPClient;
class CBaseGame;
class CCommandPacket;
struct OHCHeader {
  unsigned header_size;
  bool fin;
  bool mask;
  enum opcode_type {
    CONTINUTATION = 0x0,
    TEXT_FRAME = 0x1,
    BINARY_FRAME = 0x2,
    CLOSE = 8,
    PING = 9,
    PONG = 0xa,
  } opcode;
  uint64_t N0;
  uint64_t N;
  uint8_t masking_key[4];
};

在我的.cpp 文件中,我使用namespace std; 并包含<string> 仅用于Windows。 但到目前为止,这一切都没有奏效。我不想将整个文件放入问题中,因为它们实际上很长。 这是完整的来源: Headerfile Mainfile

我在这里做错了什么?

【问题讨论】:

  • #includeing stdint.h 应该可以修复这些错误。

标签: c++ compiler-errors


【解决方案1】:

编译器不知道uint64_tuint8_t的类型,添加:

#include <cstdint>

【讨论】:

    【解决方案2】:

    还要注意,枚举中的尾随逗号(在定义 PONG = 0xa 之后)仅在 C++11 中标准化,遵循 C99 中的更改。较旧的编译器或在遵循较旧的 1998/2003 标准的模式下运行的编译器也可能会遇到这种情况。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-12
      • 1970-01-01
      相关资源
      最近更新 更多