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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:50:35+00:00 2026-06-16T00:50:35+00:00

I have been reading C++ primer. For the initialization of object, C++ supports 2

  • 0

I have been reading “C++ primer”. For the initialization of object, C++ supports 2 forms of initialization: direct and copy.
but the book does not refer the initialization of reference. And in the book I have never seen the direct initialize(if exists) of a reference. All is the copy one like:

int i;
int &j = i;//but not int &j(i);which also works in my experiment

I want to know that is it the same that are going on underneath for the initialization of a reference.
for the following codes:

string null_book = "9-999-99999-9";

the initialization progress is first create a temporary string object tmp(for instance) that will direct initialized with a c style string parameter, and then initialize the variable null_book with the copy Constructor. That make sense to me.
for this one:

int &j = i;

will ref j be initialized the same way? That will be a temp reference it &t(for example) initialized by i and then initialize j with t? that doesnt make sense??? Why the book never use the direct initialization for reference?
Thanks for your attention!

  • 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-16T00:50:36+00:00Added an answer on June 16, 2026 at 12:50 am

    The main differences between direct-initialization and copy-initialization are covered in section 8.5, paragraph 17 of the standard. In general, the difference is that for class types in copy-initialization, explicit constructors are not considered (only converting constructors are considered) and a possibly elided copy is made; in direct-initialization explicit constructors are considered and the target is constructed directly. From section 8.5 of the standard:

    14 – The form of initialization (using parentheses or =) is generally insignificant, but does matter when the initializer or the entity being initialized has a class type […]

    For non-class types (including references), direct-initialization and copy-initialization have similar semantics; for references, a reference binding occurs in either case, as specified in 8.5.3 References [dcl.init.ref]. Direct-initialization and copy-initialization of a reference only have different semantics where a conversion function is involved (13.3.1.6 Initialization by conversion function for direct reference binding [over.match.ref]); again, direct-initialization is allowed to invoke explicit conversion functions where copy-initialization is not.

    So, in

    int &j = i;
    

    8.5.3p5 applies and the reference j is bound directly to the lvalue i. No temporaries are invoked.

    In terms of complexity, references are closer to fundamental (primitive) types than to class types. Primitives are initialized without a temporary being constructed (8.5p17, last bullet) and in general references are too. This is probably why the book only uses the = form for initialization of references; as with primitives, there is usually no difference and writing int i = x; is usually clearer than int i(x);.

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

Sidebar

Related Questions

I have been reading the Phing documentation and it makes sense, but I'm not
I have been reading around for other answers but i am still not understanding
I have been reading a book about network programming but I am confused about
I have been reading a lot about both PEP-333 and PEP-3333 . But I
I have been reading the book of Windows via C/C++. In chapter 8, page
Have been reading up and checking other questions, but don't understand / can't seem
I have been reading up on password hashing, but all the forums I read
I have been reading documents/urls and really not understand about app.use and its usage.
I have been reading timestamp values from sensor readings, but since they are provided
I have been reading a book named Teach Yourself Java in 21 days by

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.