【问题标题】:Can not define struct type: member name not declared无法定义结构类型:未声明成员名称
【发布时间】:2021-12-28 09:20:17
【问题描述】:

我尝试通过以下方式在 C++ 中定义结构类型:

struct fckxMsg_t {   
unsigned char     : status;
unsigned char     : data1;
unsigned char     : data2;
};

我的编译器抱怨:

error: 'status' was not declared in this scope unsigned char : status;

我看不出有什么问题。其实我只是想给成员一个名字。为什么之前要声明???

【问题讨论】:

  • 变量声明中没有冒号
  • 你想做什么?只定义那些结构成员?
  • 糟糕,我看到定义的第一部分不在我的帖子中。内容为:struct myStruct{
  • 好的,我明白了。它是定义中的冒号.....谢谢!
  • 我怀疑您将 C++ 与其他语言混淆了,并且会从 a good book 中受益。

标签: c++ struct


【解决方案1】:

感谢您的快速回复!

正确的代码应该是:

struct myStruct {
    unsigned char   status;
    unsigned char   data1;
    unsigned char   data2;
};

我现在可以跳到我的下一个错误 :-))

【讨论】:

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