home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!wupost!m.cs.uiuc.edu!sunb10.cs.uiuc.edu!sparc10.cs.uiuc.edu!pjl
- From: pjl@sparc10.cs.uiuc.edu (Paul Lucas)
- Subject: Re: Reference to a pointer??
- Message-ID: <1992Sep10.223528.1410@sunb10.cs.uiuc.edu>
- Keywords: pointer, reference
- Sender: news@sunb10.cs.uiuc.edu
- Organization: University of Illinois at Urbana-Champaign
- References: <ucosmo.716157377@mcl>
- Distribution: usa
- Date: Thu, 10 Sep 1992 22:35:28 GMT
- Lines: 35
-
- In <ucosmo.716157377@mcl> ucosmo@mcl.ucsb.edu (Boris Burtin) writes:
-
- >I have not been able to dig up any information on how to change a pointer
- >inside a function (aside from the good old dual-pointer C solution). I know
- >that, for example, an int can be changed in a function like so:
-
- >void f(int& i)
- >{
- > i = 0;
- >}
-
- >So why can't you do this:
-
- >void f(int& *p)
- >{
- > p = 0;
- >}
-
- >Or do I just have the syntax wrong?
-
- *****> You have the syntax wrong. C(++) is sort of the "Hebrew" of
- computer languages with regard to declarations, i.e., it makes
- more sense if you read and write them from right to left.
-
- int &*p; // right-to-left: pointer to a reference to an int
- // which is illegal since references are not
- // first-class objects
-
- int *&p; // reference to a pointer to an int: legal
-
- This is mentioned on p.29 of my book.
- --
- - Paul J. Lucas University of Illinois
- AT&T Bell Laboratories at Urbana-Champaign
- Naperville, IL pjl@cs.uiuc.edu
-