Friday, October 8, 2010

Preferred Method of Initializing

The preferred method of initializing is:
   MyClass x; MyClass y(x);
instead of:
   MyClass x; MyClass y = x;
This is in case the compiler does not optimize out the temporary when using 'y = x'.

Reference: More Exceptional C++ by Herb Sutter. Addison-Wesley, 2002., pp. 224-225.

No comments:

Post a Comment