parthi_for_tech
parthi_for_tech

Reputation: 49

class variable initialization in cpp

I have a class like this,

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;         
};

Then, what does the below code segment mean?

CLv        lvEnd = {0,0};

Upvotes: 2

Views: 90

Answers (1)

Luchian Grigore
Luchian Grigore

Reputation: 258618

It means that the variable lvEnd of type CLv is initialized with values of 0 and 0 for its members _value and _fStart.

Your class is an aggregate:

8.5.1 Aggregates [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).

And can be list-initialized:

8.5.4 List-initialization [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. [...]

Upvotes: 2

Related Questions