rvalues and member functions

This is a discussion on rvalues and member functions within the C++ Programming forums, part of the General Programming Boards category; If the following returns a temporary and you call a member function on it that modifies member data, why is ...

  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 01:24 AM.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    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, 05:33 PM
  2. benefits of a class in this case?
    By jdinger in forum C++ Programming
    Replies: 9
    Last Post: 05-24-2002, 12:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21