这个问题已经在这里有了答案: > What does a colon in a struct declaration mean, such as :1, :7, :16, or :32? 3个
“ uint isWidget:1;”中的冒号(:)运算符是什么意思?在Qt中?是“ uint isWidget:1;”相当于“ uint isWidget(1)”?
Qt中的代码是
QObjectData
{
public:
virtual ~QObjectData() = 0;
QObject *q_ptr;
QObject *parent;
QObjectList children;
uint isWidget : 1;
uint pendTimer : 1;
uint blockSig : 1;
uint wasDeleted : 1;
uint ownObjectName : 1;
uint sendChildEvents : 1;
uint receiveChildEvents : 1;
uint inEventHandler : 1;
uint inThreadChangeEvent : 1;
uint hasGuards : 1; //true iff there is one or more QPointer attached to this object
uint unused : 22;
int postedEvents;
QMetaObject *metaObject; // assert dynamic
};
解决方法:
这是C结构符号的一部分-您可以通过在属性名称后使用:numBits来指定整数字段的大小(以位为单位).
我必须假定可以在C类中使用相同的语法(我是C家伙,但是我确定这在C中也做同样的事情)