android - cpp中的类变量初始化

标签 android c++

我有一堂这样的课,

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被初始化为其值00成员_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/

相关文章:

android - Android Studio 中的 Apache POI 库错误..?

c++ - 为什么 C++ 按位 AND 运算符对不同大小的操作数表现得像这样?

c++ - 奇怪的逗号运算符行为

c++ - 如何在没有合并源代码的情况下调试 sqlite?

c++ - GLSL 删除使用过的变量

android - 在 Android 中使用 PackageManager 的目的

android - 如果在 OnCreateView 之外使用,findViewById 返回 null

c++ - 为什么我不能将两个不同的比较器传递给一个模板函数?

android - [android]如何保持与数据库的连接?

java - 如何使用监听器捕获所有运动事件