I was reading this book called 'A Tour of C++' by Bjarne Stroustrup and inside it is mentioned that there are basically two ways of initialization:
int a = 5.2; // Stores truncated value
int a{5.2}; // Compiler throws error
As you can see, the latter method is safer and recommended.
However, I have noticed that:
int a(5.2);
also works (and unlike the second version, it doesn't check if the type matches).
So, can someone please explain the third case, I mean, when it should be used and how it's different than the first case.
Aucun commentaire:
Enregistrer un commentaire