declare references to references works!

This is a discussion on declare references to references works! within the C++ Programming forums, part of the General Programming Boards category; Hi! You cannot declare references at references (eg. int& &rr = r), but this way, it works: _int main(void) _{ ...

  1. #1
    ManuelH
    Guest

    declare references to references works!

    Hi!

    You cannot declare references at references (eg. int& &rr = r), but this way, it works:


    _int main(void)
    _{
    _ int a = 1;
    _ int &r = a;
    _ int &rr = r;
    | rr++;
    | cout << a; // output: 2!
    |
    |}


    Why does this work!?
    Depends it which compiler you are using?

    regards,
    Manuel

  2. #2
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330

    ~

    You can reference a reference a reference a reference a reference... =)

    But why would you want to?
    "He who makes a beast of himself, gets rid of the pain of being a man." Dr. Johnson

  3. #3
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078

    Re: declare references to references works!

    Originally posted by ManuelH
    Hi!

    You cannot declare references at references (eg. int& &rr = r), but this way, it works:


    _int main(void)
    _{
    _ int a = 1;
    _ int &r = a;
    _ int &rr = r;
    | rr++;
    | cout << a; // output: 2!
    |
    |}


    Why does this work!?
    Depends it which compiler you are using?

    regards,
    Manuel
    That's because you're not referencing a reference. You're just referencing the variable a again.

  4. #4
    Registered User
    Join Date
    Dec 2002
    Posts
    103

    Just an added information

    Every time you are trying to perform any operation with a reference, "Despite appearances, no operator operates on a reference. The reference always refers to the object it was initialized with".

    Which just means that when ever you are trying to take a reference to (reference to an object), you are just taking reference to the object
    Have a wonderful day.... and keep smiling... you look terrific that way
    signing off...
    shiv... as i know him

  5. #5
    ManuelH
    Guest

    thx!

    -

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pressing a button works sometimes
    By johny145 in forum Windows Programming
    Replies: 14
    Last Post: 05-18-2005, 11:53 AM
  2. The Bludstayne Open Works License
    By frenchfry164 in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 11-26-2003, 10:05 AM
  3. Replies: 4
    Last Post: 02-02-2003, 04:45 AM
  4. Programs works one way, not another. VC++ 6.0 help.
    By Cheeze-It in forum Windows Programming
    Replies: 4
    Last Post: 12-10-2002, 09:29 PM
  5. Pls explain how this program works...
    By Unregistered in forum C Programming
    Replies: 9
    Last Post: 01-05-2002, 08:53 AM

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