home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13503 < prev    next >
Encoding:
Text File  |  1992-09-10  |  1.4 KB  |  49 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!wupost!m.cs.uiuc.edu!sunb10.cs.uiuc.edu!sparc10.cs.uiuc.edu!pjl
  3. From: pjl@sparc10.cs.uiuc.edu (Paul Lucas)
  4. Subject: Re: Reference to a pointer??
  5. Message-ID: <1992Sep10.223528.1410@sunb10.cs.uiuc.edu>
  6. Keywords: pointer, reference
  7. Sender: news@sunb10.cs.uiuc.edu
  8. Organization: University of Illinois at Urbana-Champaign
  9. References: <ucosmo.716157377@mcl>
  10. Distribution: usa
  11. Date: Thu, 10 Sep 1992 22:35:28 GMT
  12. Lines: 35
  13.  
  14. In <ucosmo.716157377@mcl> ucosmo@mcl.ucsb.edu (Boris Burtin) writes:
  15.  
  16. >I have not been able to dig up any information on how to change a pointer 
  17. >inside a function (aside from the good old dual-pointer C solution).  I know
  18. >that, for example, an int can be changed in a function like so:
  19.  
  20. >void f(int& i)
  21. >{
  22. >    i = 0;
  23. >}
  24.  
  25. >So why can't you do this:
  26.  
  27. >void f(int& *p)
  28. >{
  29. >    p = 0;
  30. >}
  31.  
  32. >Or do I just have the syntax wrong?
  33.  
  34. *****>    You have the syntax wrong.  C(++) is sort of the "Hebrew" of
  35.     computer languages with regard to declarations, i.e., it makes
  36.     more sense if you read and write them from right to left.
  37.  
  38.         int &*p; // right-to-left: pointer to a reference to an int
  39.              // which is illegal since references are not
  40.              // first-class objects
  41.         
  42.         int *&p; // reference to a pointer to an int: legal
  43.     
  44.     This is mentioned on p.29 of my book.
  45. -- 
  46.     - Paul J. Lucas                University of Illinois    
  47.       AT&T Bell Laboratories        at Urbana-Champaign
  48.       Naperville, IL            pjl@cs.uiuc.edu
  49.