What does this number mean in C++ class declaration?

In the following class, what does :1 mean? Thanks.
1
2
3
4
5
class X 
{
public:
   bool mIsActive:1;
};
Last edited on
It means that mIsActive is a bitfield. It is like a usual variable, but its size is 1 bit (there, but you can write a number of bits you want) and also you can't create references, pointers and arrays of bits.
You can read about it there: http://msdn.microsoft.com/en-us/library/ewwyfdbe(v=vs.71).aspx
As it stands, class X is using a pointless bitfield. sizeof(X) == sizeof(bool), but only 1 bit is being used to store info. I would hope the compiler would just ignore the bitfield in this case (to avoid unnecessary bit twiddling).

I have normally seen bitfields being using with unsigned integral types.
Topic archived. No new replies allowed.