I found many articles explaining the difference between "default-initialization and value-initialization" but in fact I didn't understand clearly.
Here's an example:
class A{
public:
int x;
};
int main(){
A a;// default initialization so x has undefined value.
A b = A(); // value initialization so x is a scalar thus it is value initialized to 0
}
Above it is OK as I guess but here:
int value = 4; // is this considered a value-initialization?
Please help me understand the major differences between the two forms of initializations.
A a;
does not have default initialisation. I thoughtA a1{};
default initialises, andA a2{1};
value initialises, andA a3{a2};
copy initialises, although the above link states thatA a1{};
is value initialised, so perhaps I'm just wrong. – TrainmanA a1{};
is value initialization, andA a2{1};
andA a3{a2};
are direct initialization. – Guffaw