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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:51:56+00:00 2026-06-12T03:51:56+00:00

When I read about copy initializing vs direct initializing here . copy constructor should

  • 0

When I read about copy initializing vs direct initializing here. copy constructor should call in copy initializing. why here copy constructor not calling?

#include <iostream>

using namespace std;

class A{};

class B{
public:
B(const A &a){cout << "B construct from A" << endl;}
B(const B &b){cout << "B copy constructor" << endl;}
};

int main(){
A a;
B b = a;
return 0;
}
  • 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-06-12T03:51:57+00:00Added an answer on June 12, 2026 at 3:51 am

    This is Copy ElisionRef 1:.
    Copy constructor calls while generating temporaries might be optimized by the compiler by creating objects inline and it is explicitly allowed by the C++ Standard.

    This is nicely demonstrated in the standard with an example as well:

    C++03 Standard 12.2 Temporary objects [class.temporary]
    Para 2:

    [Example:
    class X {
        // ...
        public:
        // ...
        X(int);
        X(const X&);
        ˜X();
    };
    X f(X);
    
    void g()
    {
        X a(1);
        X b = f(X(2));
        a = f(a);
    }
    

    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. Also, a temporary might be used to hold the result of f(X(2)) before copying it to `b usingX’s copyconstructor; alternatively,f()’s result might be constructed in b. On the other hand, the expressiona=f(a)requires a temporary for either the argument a or the result off(a)to avoid undesired aliasing ofa`. ]

    Ref 1:
    C++03 12.8 Copying class objects [class.copy]
    Para 12:

    When certain criteria are met, an implementation is allowed to omit the copy construction of a class object, even if the copy constructor and/or destructor for the object have side effects…..

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

Sidebar

Related Questions

I want integrate CPD (Copy-Paste-Detection) to my iOS project. I read about it here
I read about using <context:component-scan base-package=tld.mydomain.business> <context:include-filter type=annotation expression=org.springframework.stereotype.Service/> </context:component-scan> and annotate my service
I just read an article that explains the zero-copy mechanism. It talks about the
Read about Server push here . I want to push data to client from
I read about Big-O Notation from here and had few questions on calculating the
I read about __packed__ from here and, I understood that when __packed__ is used
I've read about the jQuery.ajax method and believe this should be what I need
I have read many topics about cut/copy to clipboard, but haven't found the answer
Update: This issue has been resolved. you can read about the solution in here:
Read about the issue in this stackoverflow question . Still have the same issue

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.