reference types

Discussion in 'C++' started by Daniel Oberhoff, May 17, 2008.

  1. 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.
     
    Daniel Oberhoff, May 17, 2008
    #1
    1. Advertising

  2. Daniel Oberhoff

    WaterWalk Guest

    On May 17, 11:17 pm, Daniel Oberhoff <> 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.
     
    WaterWalk, May 19, 2008
    #2
    1. Advertising

  3. On 2008-05-17 17:41:35 +0200, "Daniel T." <> said:

    > Daniel Oberhoff <> 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
     
    Daniel Oberhoff, May 19, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sathyaish
    Replies:
    2
    Views:
    601
    Sathyaish
    May 22, 2005
  2. Soren Kuula
    Replies:
    2
    Views:
    576
    Henry S. Thompson
    Dec 1, 2005
  3. Jeremy Cowles

    STD types vs C++ intrinsic types

    Jeremy Cowles, Aug 18, 2003, in forum: C++
    Replies:
    5
    Views:
    1,909
    Bob Jacobs
    Aug 19, 2003
  4. Steve Knight
    Replies:
    2
    Views:
    779
    Steve Knight
    Oct 10, 2003
  5. Sam Kong
    Replies:
    12
    Views:
    296
    John G Harris
    Oct 17, 2006
Loading...

Share This Page