c++ - 错误 : expected ',' or '...' before 'Hash_Flag'

标签 c++ struct enums

<分区>

我有一个结构,定义为

typedef struct
{
  char* p_hash_start_position;
  size_t hash_capacity;

  //still a flag is needed since we might start from an empty container.
  Hash_Flag hash_status;

  char* p_start_position;
  char* p_current_position;
  size_t capacity;//tagged data capacity
} tagged_data_t;  

枚举定义为

typedef enum Hash_Flag
{
    TD_HASH,
    TD_NO_HASH
} Hash_Flag;

为什么会出现以下错误?

error: expected ',' or '...' before 'Hash_Flag'

最佳答案

enum Hash_Flag 的定义应该先于它的使用。重新排列代码,使结构定义遵循 enum Hash_Flag

typedef enum Hash_Flag
{
    TD_HASH,
    TD_NO_HASH
} Hash_Flag;

typedef struct
{
  char* p_hash_start_position;
  size_t hash_capacity;

  //still a flag is needed since we might start from an empty container.
  Hash_Flag hash_status;

  char* p_start_position;
  char* p_current_position;
  size_t capacity;//tagged data capacity
} tagged_data_t;

如果我编写如下代码,我可以重现您报告的问题:

  1  typedef enum Hash_Flag
  2  {
  3      TD_HASH,
  4      TD_NO_HASH
  5  } Hash_Flag;
  6
  7  int foo(int x Hash_Flag) {}

$ g++ -c t.cc
t.cc:7: error: expected ',' or '...' before 'Hash_Flag'

您应该转到编译器错误报告的精确代码行,看看您是否可以看到函数参数之间缺少逗号。

如果您没有在编译器报告错误的代码行中发现明显缺失的逗号,则错误可能是由于扩展宏引起的。尝试让编译器为您扩展宏,以便您可以观察扩展后的代码。使用 g++,您将传递 -E 标志以生成在所有宏展开后源代码将展开的内容。

关于c++ - 错误 : expected ',' or '...' before 'Hash_Flag' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25191757/

相关文章:

c++ - 有没有一种直观的方法来检查标志和状态?

c++ - 如何使用结构 vector 作为参数从node-ffi调用c++中的方法?

c++ - move std::vector 时出现段错误

c++ - EOF - scanf 和 printf

更改指向结构的指针,通过引用传递

c - 同时访问一个 c union 的不同成员

c++ - 在 Qt 中使用 Botan 时遇到问题

c - 使用 。检索结构中的值

swift - 禁止 swift 中间接枚举的一些特定情况

json - 如何在Dart中使用枚举的属性名称将JSON映射到对象