I’m trying to understand what the following line does:
BStats stats = BStats();
The struct is defined as follows:
struct BStats
{
unsigned a;
unsigned b;
BStats& operator+=(const BStats& rhs)
{
this->a += rhs.a;
this->b += rhs.b;
return *this;
}
};
But I have no idea about what this line does. Is it calling the default constructor?
The expression
BStats()is described in the standard in 5.2.3/2:That is, the expression creates an rvalue of
Bstatstype that is value-initialized. In your particular case, value-initialization means that the two members of theBStatsstruct will be set to zero.Note that this is different than the behavior of calling the default-constructor that is mentioned in other answers, as the default constructor will not guarantee that the members are set to 0.