Reputation: 195
I can't understand this; please describe it. This is C++ code:
int upper(0), lower(0);
Upvotes: 0
Views: 81
Reputation: 2438
As noted in @dxiv's comment, this is direct initialization of the upper and lower variables. The following syntax is also direct initialization:
int even_lower{0};
when applied to non-class type objects. When applied to objects of class type, it invokes the relevant constructor or conversion operator.
Upvotes: 4
Reputation: 610
I will try to add all possible ways to assign a variable in here with the difference
1
int upper=0, lower=0;
will assign upper as 0 and lower as 0
2 constructor initialization with single value
int upper(0), lower(0);
will assign upper as 0 and lower as 0
3 constructor initialization with multiple values will initialize a variable with the last value
int upper=(0,1,2,3), lower=(44,55,6,77,-5);
will assign upper as 3 and lower as -5
4 Uniform Initialization takes only single value you can't have multiple values in here
int upper{0}, lower{0};
will assign upper as 0 and lower as 0
5 you can use = in both constructor and uniform initialization for single values
int upper={0}, lower={0};
will assign upper as 0 and lower as 0
Upvotes: 1