When initializing primitive types like int
or pointers one can use either copy-initialization or direct-initialization.
int a = 10;
int b(10);
Although the latter way is preffered for objects with constructors, I don't see people using it for primitives. I understand that it is kind of "more natural" (especially for numbers) to use the '=' operator but is there anybody writing things like in real-life code:
for (int i(0); i < 5; ++i) {
cout << i << endl;
}
Thanks.
EDIT: The question asks about coding styles and best practices rather than technical implementation.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…