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

  • Home
  • SEARCH
  • 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 6992575
In Process

The Archive Base Latest Questions

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

How do temporary objects get created during reference initialization by the compiler, and what

  • 0

How do temporary objects get created during reference initialization by the compiler, and what does that mean?

EDIT

From the C++ standard:

12.2 Temporary objects [class.temporary] Temporaries of class type are created in various
contexts: binding a reference to a prvalue (8.5.3), returning 1 a
prvalue (6.6.3), a conversion that creates a prvalue (4.1, 5.2.9,
5.2.11, 5.4), throwing an exception (15.1), entering a handler (15.3), and in some initializations (8.5).

From this link: http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8l.doc%2Flanguage%2Fref%2Fcplr382.htm

When a temporary object is created to initialize a reference variable,
the name of the temporary object has the same scope as that of the
reference variable.

  • 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-27T19:39:10+00:00Added an answer on May 27, 2026 at 7:39 pm

    From your edit: 12.2 states that a temporary is created in the cases when you initialize a const reference where it refers to a prvalue. For example:

    double d = 3.14;
    const int &r = d;
    

    the compiler transforms this code into something like this:

      int temp = d;         // creates a temporary int
      const int &r = temp;  // reference is bound to that temporary
    

    The lifetime of temporary that is bound to a const reference is the lifetime of the reference. i.e. the temporary is destroyed when the reference goes out of the scope.

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

Sidebar

Related Questions

Does C++ provide a guarantee for the lifetime of a temporary variable that is
In my project I have some objects that I show from a server, lets
UltraEdit saves temporary, ie. unsaved/untitled, files as (regex) Edit.\d+. When UltraEdit is killed (I
Using an Oracle temporary table does not generate much redo log as a normal
I am iterating over, and modifying a map (which is created from an existing
I have a Node class that has an 'element' slot which contains a list
I'm trying to create a factory_build class method for creating Redirect objects within an
I have such views: def finish_creation(request, pre_id): pre_post = PrePost.objects.get(pk = pre_id) if pre_id
Ok, so I want to have a report that does not require the end
I am working on creation of temporary tables in sql server. I created the

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.