0

I try to define a struct type in C++ in the following way:

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

My compiler complains with:

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

I don't see what is wrong. Actually I just want to give the members a name. Why should it have been declared before???

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
f ckx
  • 49
  • 1
  • 6
  • 3
    Variable declarations don't have a colon in them – Alan Birtles Nov 17 '21 at 11:38
  • What you are trying to do? Just define those structure members? – kiner_shah Nov 17 '21 at 11:38
  • Oops, I see that the first part of the definition is not in my post. It reads: struct myStruct{ – f ckx Nov 17 '21 at 11:39
  • OK, I see. It is the colons inside the definition..... Thanks! – f ckx Nov 17 '21 at 11:40
  • I suspect that you're confusing C++ with some other language and would benefit from [a good book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – molbdnilo Nov 17 '21 at 12:06
  • You are right about confusing. The problem is in the fact that for my project I have to switch between multiple platforms/languages all the time. – f ckx Nov 18 '21 at 22:17

1 Answers1

0

Thanks for your quick response!

The correct code should be:

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

I can now jump to my next bug :-))

f ckx
  • 49
  • 1
  • 6