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 6928245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:09:41+00:00 2026-05-27T11:09:41+00:00

If a have a class with both standard and copy constructors class Ex{ //constructor

  • 0

If a have a class with both standard and copy constructors

class Ex{
       //constructor definitions
}

and a function that takes it as an argument (by value)

void F(Ex _exin){...}

take the following piece of code:

Ex A;
F(A);   //F's parameter is copy constructed from A
F(Ex());  //F's parameter uses the default constructor

In the third line I’m passing to F a new (temporary) object of the Ex class using the default constructor. My question is: after this new object is created is it also copy constructed/assigned (like it happens in the second line) or is it directly created “inside” F?

  • 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-27T11:09:42+00:00Added an answer on May 27, 2026 at 11:09 am

    It was hard to find, but honestly it was bugging me. This is called copy constructor elision.

    The standard illustrates this example:

    class X{
    public:
       X(int);
       X(const X&);
       ~X()
    };
    
    X f(X);
    
    void g()
    {
       X a(1);
       X b = f(X(2)); //identical to what you have:
       a = f(a);
    }
    

    And it states:

    12.2/2 Temporary objects

    Here, an implementation might use a temporary in which to construct
    X(2) before passing it to f() using X’s copy-constructor;
    alternatively, X(2) might be constructed in the space used to hold the
    argument. /…/

    After this the standard explains return value optimization, which is basically the same thing.

    So it actually has nothing to do with observed behavior, it is up to the compiler.

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

Sidebar

Related Questions

What if I have a class that both extends an abstract class and implements
We have two projects that are both class libraries. Project 1 is a VS
I have a parent and child class that both need to implement IDisposable .
I have a class that contains two sets. They both contain the same key
I have a template class that has a template member function that needs to
I have a class with both a static and a non-static interface in C#.
Say I have three classes: class X{}; class Y{}; class Both : public X,
I have a class with a string property, having both a getter and a
I have an anonymous inner class inside another class ( SomeClass ). Both SomeClass.class.getClasses()
I have three classes; Classes A and B both reference class C . How

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.