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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:19:47+00:00 2026-06-06T11:19:47+00:00

class A {}; class B { public: B (A a) {} }; A a;

  • 0
class A {};
class B { public: B (A a) {} };

A a;
B b=a;

Technically speaking, is a copy constructor being applied here on the creation of b ?

  • 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-06T11:19:49+00:00Added an answer on June 6, 2026 at 11:19 am

    Technically speaking, is a copy constructor being applied here on the creation of b ?

    Yes…but probably not how you think. A‘s copy constructor is being invoked on the creation of b, in order to do the pass-by-value of the parameter A a as a parameter to the B constructor.

    However, it is not running B’s copy constructor in the creation of b.


    EDIT: One learns something new every day. Apparently even more-technically-speaking, as @CharlesBailey pointed out…if you use the B b = a; syntax (“copy initialization”) instead of B b (a); syntax (“direct initialization”), a temporary value of type B might need to be created. At this point B’s copy constructor would wind up being called.

    It’s a little hard to study the phenomenon, but Charles points out that gcc has a -fno-elide-constructors option (also: Wikipedia on Copy Elision) @JesseGood’s link has an exhaustive explanation and some demonstration code:

    Is there a difference in C++ between copy initialization and direct initialization?

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

Sidebar

Related Questions

Here's the code I have: =========================== public class Foo { //Class field to store
Simple class public class Group { public Int16 ID { get; private set; }
I have the following class public class UIControl { public string FName{ get; set;
Having the following class: public class SomeClass { private readonly int[] _someThings; public SomeClass()
I have following class public class ButtonChange { private int _buttonState; public void SetButtonState(int
Suppose the following class public class Message { // some code } And a
I have this class: public static class CsvWriter { private static StreamWriter _writer =
In the following class: public class Example<T> where T : IComparable { private T
I have such a class: public class Cycle { public List<int> Edges { get;
Given this class public partial class Default : Page { private IRepository repo; ...

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.