0

I can understand the purpose of having a colon after constructor in Cpp. (What is this weird colon-member (" : ") syntax in the constructor?). But what is the purpose of the format, datatype colon value as following

unsigned AttrKind : 8;

I found this in private variables of a class. I have only a basic idea of Cpp and its not digesting for me.

If I am not wrong, its not a bit field as this variable is not declared inside a structure. its in the private section of a class

Community
  • 1
  • 1
Ginu Jacob
  • 1,588
  • 2
  • 19
  • 35
  • It's a [bit field](http://en.cppreference.com/w/cpp/language/bit_field). `AttrKind` is to only take up 8 bits. Dunno why they didn't just use [`uint8_t`](http://en.cppreference.com/w/cpp/types/integer). – BoBTFish Jan 14 '16 at 14:59
  • See http://en.cppreference.com/w/cpp/language/bit_field – Danny_ds Jan 14 '16 at 15:00
  • It's not a bitstream. The thing is its just in the private section of a class and is not part of any structure – Ginu Jacob Jan 14 '16 at 15:07
  • 2
    @GinuJacob: In C++, both `struct` and `class` declare compound objects; either can include bit fields. The only difference between `struct` and `class` is the default visibility. – rici Jan 14 '16 at 15:11

0 Answers0