int x(0)
and I told him I liked the way it looked over int x = 0
. He told me it was good I did it this way and explain to the class why. int x(0)
vs int x = 0
?
|
|
My question is what are the pros and cons of declaring a variable like int x(0) vs int x = 0? |
|
|
=
in different contexts is a different thing. Oh, and the mistyped equality operator ...int x(0)
int x = 0
int x(0) Is a direct initialization. int x = 0 Is a copy initialization, it involves extra copying and moving than the direct method. Compilers usually optimize a copy initialization to a direct one, but the only way to be sure is to do it by yourself. |