Thread: rvalues and member functions

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    135

    rvalues and member functions

    If the following returns a temporary and you call a member function on it that modifies member data, why is it legal when the temporary is an rvalue? Remember, temporaries can't be bound to non-const references - to prevent modification - because they're non-addressable just like a literal number 5 is (at least conceptionally). So why is this allowed, when the other is not and they're both rvalues?

    Code:
    class X{...};
    
    X().ModifyMembers(); // modifies member data of a temporary object
    Last edited by xeddiex; 10-22-2006 at 12:24 AM.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    In short, probably so that proxies can work.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 04:33 PM
  2. benefits of a class in this case?
    By jdinger in forum C++ Programming
    Replies: 9
    Last Post: 05-24-2002, 11:04 AM