I'm currently reading in "The C++ Programming Language: Special Edition" by Bjarne Stroustrup and on page 133 it states the following:
For user-defined types, postponing the definition of a variable until a suitable initializer is available can also lead to better performance. For example:
string s; /* .... */ s = "The best is the enemy of the good.";
can easily be much slower than
string s = "Voltaire";
I know it states can easily, which means it won't necessarily be so, however let's just say it does occur.
Why would this make a potential performance increase?
Is it only so with user-defined types (or even STL types) or is this also the case with int
, float
, etc?