Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > reference types

Reply
Thread Tools

reference types

 
 
Daniel Oberhoff
Guest
Posts: n/a
 
      05-17-2008
Hi,

Can someone more proficient in the details of the c++ type system
please tell me how I can instantiate the for constesses of references
that I think should be possible:

1. non-constant reference to non-constant value
2. constant reference to non-constant value
3. non-constant reference to constant value
4. constant reference to constant value

const T & seems to behave like the latter, and I could not find any
good reference on this. I would like to be able to use references to
non-const rvalues.

 
Reply With Quote
 
 
 
 
WaterWalk
Guest
Posts: n/a
 
      05-19-2008
On May 17, 11:17 pm, Daniel Oberhoff <(E-Mail Removed)> wrote:
> Hi,
>
> Can someone more proficient in the details of the c++ type system
> please tell me how I can instantiate the for constesses of references
> that I think should be possible:
>
> 1. non-constant reference to non-constant value
> 2. constant reference to non-constant value
> 3. non-constant reference to constant value
> 4. constant reference to constant value
>
> const T & seems to behave like the latter, and I could not find any
> good reference on this. I would like to be able to use references to
> non-const rvalues.


Not like a pointer, a reference must refer to something. If the object
is const, the reference must be const qualified. But if the object
isn't const, the reference can be either const or non-const qualified.
 
Reply With Quote
 
 
 
 
Daniel Oberhoff
Guest
Posts: n/a
 
      05-19-2008
On 2008-05-17 17:41:35 +0200, "Daniel T." <(E-Mail Removed)> said:

> Daniel Oberhoff <(E-Mail Removed)> wrote:
>
>> Can someone more proficient in the details of the c++ type system
>> please tell me how I can instantiate the for constesses of references
>> that I think should be possible:
>>
>> 1. non-constant reference to non-constant value
>> 2. constant reference to non-constant value
>> 3. non-constant reference to constant value
>> 4. constant reference to constant value
>>
>> const T & seems to behave like the latter, and I could not find any
>> good reference on this. I would like to be able to use references to
>> non-const rvalues.

>
> There is no such thing as a "non-constant" reference, so 1 and 3 above
> are impossible.
>
> 2. "T&"
> 4. "const T&"
>
> If you think you need a non-constant reference, use a pointer.


ah, ha! I always thought you could change the referee of a reference,
thus the reference could be non-const referring to several const
referees in its lifetime (this is a strange use of the word referee as
"reffered-to-object", but it feels like proper use of english
construction rules...is it?). but actually reading another post and
thinking about it I realized it is not, since the reference inherits
the operator= from the referee. I suppose I got used to the idea since
I deal with blitz arrays a lot, which use refcounted storage and the
target storage can be changed, which is like changing the referee, but
explicitly using a function call. ah well . Though while at it: I
know in c++ it is not allowed to (non-const) reference an rvalue,
though there are times when it makes sense to modify and rvalue, while
not wanting to copy it. Though I suppose this would have to involve
refcounting...

Daniel

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Questions about memory structure of value types and reference types Sam Kong Javascript 12 10-17-2006 07:26 PM
Can XSD simple types be derived from complex types? Soren Kuula XML 2 12-01-2005 07:51 PM
Where are ref types that are members of value types stored? Sathyaish ASP .Net 2 05-22-2005 07:32 PM
Boost + Python C/API: Mixing python return types with boost return types Steve Knight Python 2 10-10-2003 10:11 AM
STD types vs C++ intrinsic types Jeremy Cowles C++ 5 08-19-2003 05:33 PM



Advertisments