Yes, there may be a difference.
In the first case, myObj
not initialized if it is a POD type, otherwise it is initialized by default.
The second instance of myObj
initializes the copy from the initialized value. A temporary possibility (and almost certainly should) be eliminated in order to initialize the effect value.
If myObj
has a constructor, then the constructor will always be called. For the first case, the default constructor should be available, for the second, both copy and default constructors should be available, although only the default constructor can be called.
In addition to the obvious difference between “uninitialized” and initialized values for POD types, there is a difference between default initialization and value initialization for non-POD types without user-defined constructors. For these types, POD members are not initialized with default initialization, but are initialized with the zero initialization value of the parent class.
Charles Bailey
source share