Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #11616

Mutability of temporary variables

Newsgroups comp.lang.c++
Date 2011-11-19 13:33 +0100
Subject Mutability of temporary variables
From kyle <kyle@nomail.com>
Organization none
Message-ID <op.v4605gilpbcp0d@localhost.localdomain> (permalink)

Show all headers | View raw


Consider following code:

int main() {
   const int& c = int();
   int& m = const_cast<int&>(c);
   m = 4;
}

The object of the snippet is to get a mutable reference to a temporary.
This cant be done directly because non-const reference cannot bind to  
temporary, but we should be OK with casting away constness of reference  
'c' since it doesn't actually refer to const object.

Temporaries are mutable, so in whole my snippet is legal C++. Am i correct?

-- 
kyle

Back to comp.lang.c++ | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Mutability of temporary variables kyle <kyle@nomail.com> - 2011-11-19 13:33 +0100
  Re: Mutability of temporary variables Paavo Helde <myfirstname@osa.pri.ee> - 2011-11-19 07:18 -0600
    Re: Mutability of temporary variables Victor Bazarov <v.bazarov@comcast.invalid> - 2011-11-19 08:45 -0500
      Re: Mutability of temporary variables Leigh Johnston <leigh@i42.co.uk> - 2011-11-19 14:25 +0000
        Re: Mutability of temporary variables "Paul" <pchrist<nospam>or@yahoo.co.uk> - 2011-11-20 00:14 +0000
          Re: Mutability of temporary variables Leigh Johnston <leigh@i42.co.uk> - 2011-11-20 00:45 +0000
            Re: Mutability of temporary variables Leigh Johnston <leigh@i42.co.uk> - 2011-11-20 01:14 +0000
              Re: Mutability of temporary variables "Paul" <pchrist<nospam>or@yahoo.co.uk> - 2011-11-20 02:34 +0000
                Re: Mutability of temporary variables "Paul" <pchrist<nospam>or@yahoo.co.uk> - 2011-11-20 02:44 +0000
                Re: Mutability of temporary variables Leigh Johnston <leigh@i42.co.uk> - 2011-11-20 13:06 +0000
                Re: Mutability of temporary variables Leigh Johnston <leigh@i42.co.uk> - 2011-11-20 13:21 +0000
                Re: Mutability of temporary variables "Paul" <pchrist<nospam>or@yahoo.co.uk> - 2011-11-20 16:51 +0000
                Re: Mutability of temporary variables Leigh Johnston <leigh@i42.co.uk> - 2011-11-20 17:24 +0000
      Re: Mutability of temporary variables SG <s.gesemann@gmail.com> - 2011-11-20 00:49 -0800
  Re: Mutability of temporary variables Victor Bazarov <v.bazarov@comcast.invalid> - 2011-11-19 08:42 -0500
    Re: Mutability of temporary variables Paavo Helde <myfirstname@osa.pri.ee> - 2011-11-19 08:20 -0600
      Re: Mutability of temporary variables Victor Bazarov <v.bazarov@comcast.invalid> - 2011-11-19 15:51 -0500
        Re: Mutability of temporary variables Paavo Helde <myfirstname@osa.pri.ee> - 2011-11-19 16:51 -0600
        Re: Mutability of temporary variables "Paul" <pchrist<nospam>or@yahoo.co.uk> - 2011-11-20 00:23 +0000
  Re: Mutability of temporary variables Johannes Schaub <schaub.johannes@googlemail.com> - 2011-11-19 16:16 +0100
    Re: Mutability of temporary variables "Paul" <pchrist<nospam>or@yahoo.co.uk> - 2011-11-20 00:31 +0000
    Re: Mutability of temporary variables kyle <kyle@nomail.com> - 2011-11-24 00:50 +0100
      Re: Mutability of temporary variables Johannes Schaub <schaub.johannes@googlemail.com> - 2011-11-24 20:36 +0100
  Re: Mutability of temporary variables SG <s.gesemann@gmail.com> - 2011-11-21 01:17 -0800
    Re: Mutability of temporary variables Johannes Schaub <schaub.johannes@googlemail.com> - 2011-11-22 23:26 +0100

csiph-web