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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:08:05+00:00 2026-05-15T07:08:05+00:00

I believe the expression T() creates an rvalue (by the Standard). However, the following

  • 0

I believe the expression T() creates an rvalue (by the Standard). However, the following code compiles (at least on gcc4.0):

class T {};

int main()
{
    T() = T();
}

I know technically this is possible because member functions can be invoked on temporaries and the above is just invoking the operator= on the rvalue temporary created from the first T().

But conceptually this is like assigning a new value to an rvalue. Is there a good reason why this is allowed?

Edit: The reason I find this odd is it’s strictly forbidden on built-in types yet allowed on user-defined types. For example, int(2) = int(3) won’t compile because that is an “invalid lvalue in assignment”.

So I guess the real question is, was this somewhat inconsistent behavior built into the language for a reason? Or is it there for some historical reason? (E.g it would be conceptually more sound to allow only const member functions to be invoked on rvalue expressions, but that cannot be done because that might break some existing code.)

  • 1 1 Answer
  • 1 View
  • 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-15T07:08:06+00:00Added an answer on May 15, 2026 at 7:08 am

    This is why several classes in the Standard library can be implemented. Consider for example std::bitset<>::operator[]

    // bit reference:
    class reference {
      friend class bitset;
      reference();
    public:
      ˜reference();
      reference& operator=(bool x);           // for b[i] = x;
      reference& operator=(const reference&); // for b[i] = b[j];
      bool operator˜() const; // flips the bit
      operator bool() const;  // for x = b[i];
      reference& flip();      // for b[i].flip();
    };
    
    reference operator[](size_t pos); // for b[i];
    

    If you do bits[i] = true you exactly assign some value to an rvalue of class type. The proxy that’s returned by operator[] can access the bits which are space efficiently packed into integers.

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

Sidebar

Related Questions

I have the following code that builds an IQueryable Expression<Func<TParentEntity, TChildEntity, bool>> joinExpr =
I want to convert some VB.NET code for regular expression to F#. The following
I'd like to accomplish what this (invalid I believe) regular expression tries to do:
This is the code I need to alter: var xParam = Expression.Parameter(typeof(E), typeof(E).Name); MemberExpression
I know that there are several very similarly-related questions on this website, however after
I've been given the following regex expression: if (preg_match_all('(http://)?(www[.])?(youtube|vimeo)[^\s]+'is,$prova,$n)) { foreach ($n[3] as $key
I believe you can edit the template for the BusyIndicator, however, I do not
I believe I am passing a String array from Class A to Class B
In R, I have the following expression for which I would like to take
I believe the application has some parts that target .NET, and some that don't.

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.