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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:55:34+00:00 2026-05-28T07:55:34+00:00

Why the B(B&) ctor is called, instead of B(const B&) , in the construction

  • 0

Why the B(B&) ctor is called, instead of B(const B&), in the construction of object b1 ?

#include <iostream>
using namespace std;

struct B
{
    int i;
    B() : i(2) { }
    B(B& x) : i(x.i) { cout << "Copy constructor B(B&), i = " << i << endl; }
    B(const B& x) : i(x.i) { cout << "Copy constructor B(const B&), i = " << i << endl; }
};

int main()
{
    B b;
    B b1(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-05-28T07:55:35+00:00Added an answer on May 28, 2026 at 7:55 am

    13.3.3.2/3 says

    Two implicit conversion sequences of the same form are indistinguishable conversion sequences unless one
    of the following rules apply:

    — Standard conversion sequence S1 is a better conversion sequence than standard conversion sequence
    S2 if :

    S1 and S2 are reference bindings (8.5.3), and the types to which the references refer are the same
    type except for top-level cv-qualifiers, and the type to which the reference initialized by S2 refers is
    more cv-qualified than the type to which the reference initialized by S1 refers. [Example:

    int f(const int &);
    int f(int &);
    ...
    int i;
    int j = f(i); // calls f(int&)
    

    In your case since the argument is non-const, the non-const version of the copy c-tor is chosen because it is a better match.

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

Sidebar

Related Questions

Consider the sample code below: #include <iostream> using namespace std; class core { public:
Using MSVC2010... I have a struct that wraps a std::string, with standard move ctor's
I have a class called Fraction : #ifndef FRACTION_H #define FRACTION_H #include <iostream> using
Given class: class C { public: C() { cout << Dflt ctor.; } C(C&
I have the following: typedef std::function<void(const EventArgs&)> event_type; class Event : boost::noncopyable { private:
Suppose I have this class: class foo { public: foo() { } foo(const std::string&
Got the following warning output when using GCC 4.5.0 & MinGW. Warning: .drectve `-aligncomm:___CTOR_LIST__,2
I have defined the following CComPtr object and method in my class: private: CComPtr<IRawPdu>&
Situation I'm generating wrappers by using the ILGenerator. I use Object.Equals(Object, Object) For the
consider the following: class X { public: X(int i) { cout << X(int i)

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.