我有一堂这样的课,
class CLv
{
public:
BOOL operator == (const CLv& lv) const
{
return _value == lv._value && _fStart == lv._fStart;
}
BOOL operator != (const CLv& lv) const
{
return _value != lv._value || _fStart != lv._fStart;
}
BYTE _value;
BYTE _fStart :1;
};
那么,下面的代码段是什么意思呢?
CLv lvEnd = {0,0};
最佳答案
这意味着CLv
类型的变量lvEnd
被初始化为其值0
和0
成员_value
和_fStart
。
你的类是一个集合:
8.5.1 聚合 [dcl.init.aggr]
1) An aggregate is an array or a class (Clause 9) with no user-provided constructors (12.1), no brace-or-equalinitializers for non-static data members (9.2), no private or protected non-static data members (Clause 11), no base classes (Clause 10), and no virtual functions (10.3).
并且可以列表初始化:
8.5.4 列表初始化 [dcl.init.list]
1) List-initialization is initialization of an object or reference from a braced-init-list. Such an initializer is called an initializer list, and the comma-separated initializer-clauses of the list are called the elements of the initializer list. [...]
关于android - cpp中的类变量初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12911527/