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/

相关文章:

c++ - 链接时的waf : "undefined reference" error

android - 桌面版 GCM 客户端

android - 电话 : numeric keyboard for text input

c++ - 如何将参数传递给Google Benchmark计划

c++ - 理解 C++ 中显式构造函数的问题

c++ - 我可以在枚举中放置一个转换运算符以将其转换为不同的类型吗?

android - 如何最小化所有打开的应用程序并显示主屏幕?

java - 在 HTC Desire with Android 2.2 上使用 Android MediaPlayer 进行流式传输时出现奇怪的行为

Android 相机预览拍摄的图像在特定设备上不显示

android - 零星的 IllegalArgumentException : Unknown URL content://