Assume I want to define two variables of class {Type}. The constructor takes 1 argument. Are the following two ways completely equivalent (compile to the same object code)?
Type a(arg), b(arg);
and
Type a(arg);
Type b(arg);
This question emerges after I read a page talking about exception safety --- http://www.gotw.ca/gotw/056.htm There is a guideline "Perform every resource allocation (e.g., new) in its own code statement which immediately gives the new resource to a manager object." It gives an example: The following snippet is safe
auto_ptr<T> t1( new T );
auto_ptr<T> t2( new T );
f( t1, t2 );
But the line below is not safe
f( auto_ptr<T>( new T ), auto_ptr<T>( new T ) );
So, how about
auto_ptr<T> t1( new T ), t2( new T );
f( t1, t2 );
I've looked up the document of C++ language standard, but found nothing specifying this issue.
To muddy the water, how about
shared_ptr<T> t1( new T );
shared_ptr<T> t2( t1 );
and
shared_ptr<T> t1( new T ), t2( t1 );