Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6904045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:00:04+00:00 2026-05-27T08:00:04+00:00

Assume I want to define two variables of class {Type}. The constructor takes 1

  • 0

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 );
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:00:04+00:00Added an answer on May 27, 2026 at 8:00 am

    Yes, they are equivalent. See C++11, 8/3:

    Each init-declarator in a declaration is analyzed separately as if it
    was in a declaration by itself97.

    Footnote 97 is fairly lengthy, it says that T D1, D2, ... Dn; is “usually” equivalent to T D1; T D2; ... T Dn;, with the exceptions being cases where the meaning of T in subsequent declarations is affected by which one you do. The two examples given:

    struct S {};
    S S, T; // is not equivalent to:
    S S; S T;
    
    auto i = 1, j = 2.0; // is not equivalent to:
    auto i = 1; auto j = 2.0;
    

    But in both cases, one of the alternatives is an error, so this isn’t a difference that’ll result in you having to fire up the debugger.

    Anyway yes, auto_ptr<T> t1( new T ), t2( new T ); is just as safe as auto_ptr<T> t1( new T ); auto_ptr<T> t2( new T );

    Note that there is no guarantee that equivalent source compiles to the same object code, only that it has the same meaning. In your example, object code that contains debugging annotations would reasonably differ in terms of source line numbers, but the compiler might also introduce unexpected differences for some obscure reason or for no good reason at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to calculate the angle between two vectors a and b. Lets assume
I want build a sketch pad app on iPhone, I assume that this type
Assume the following schema class Person{ public int Id {get;set;} public virtual ICollection<Province> Provinces
How to Define or Implement C# Property in ISO C++ ? Assume following C#
Assume I want to generate an element similar to this in ASP.NET MVC 2:
Assume that I want to listen to a non-common port (9090 for example) 24/7
assume I have a string 1,2,3,4 Now I want to replace, e.g. the 3rd
Assume I have an enum, and I want each enum value to be associated
Lets assume I get an HTML table as a string, and I want -
For this question, let us assume that we will want to show the face

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.