Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #11796
| From | Johannes Schaub <schaub.johannes@googlemail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Mutability of temporary variables |
| Date | 2011-11-24 20:36 +0100 |
| Organization | albasani.net |
| Message-ID | <jam2ml$rm2$1@news.albasani.net> (permalink) |
| References | <op.v4605gilpbcp0d@localhost.localdomain> <ja8dkh$snr$1@news.albasani.net> <op.v5fa6tmvpbcp0d@localhost.localdomain> |
kyle wrote:
> Dnia 19-11-2011 o 16:16:45 Johannes Schaub
> <schaub.johannes@googlemail.com> napisaĆ(a):
>
>> kyle wrote:
>>
>>> Consider following code:
>>>
>>> int main() {
>>> const int& c = int();
>>> int& m = const_cast<int&>(c);
>>> m = 4;
>>> }
>>>
>>
>> The error in your thinking is that you think that "int()" is a temporary
>> object.
>>
>
> This is indeed what i assumed.
> As i understand, i could 'fix' the code by having a function 'int foo()
> {return 1;}' and using it in place of 'int()'?
>
No, as someone else already said, rvalues of non-class and non-array type
are not objects, and the rules for initialization of references adequately
are worded to take that into account. It will behave exactly like the
"int()" case.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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