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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
  3. From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
  4. Subject: Re: Reference to a pointer??
  5. Message-ID: <9225519.23036@mulga.cs.mu.OZ.AU>
  6. Keywords: pointer, reference
  7. Sender: news@cs.mu.OZ.AU
  8. Organization: Computer Science, University of Melbourne, Australia
  9. References: <ucosmo.716157377@mcl>
  10. Date: Fri, 11 Sep 1992 09:20:45 GMT
  11. Lines: 33
  12.  
  13. ucosmo@mcl.ucsb.edu (Boris Burtin) writes:
  14.  
  15. >I have not been able to dig up any information on how to change a pointer 
  16. >inside a function (aside from the good old dual-pointer C solution).  I know
  17. >that, for example, an int can be changed in a function like so:
  18. >
  19. >void f(int& i)
  20. >{
  21. >    i = 0;
  22. >}
  23. >
  24. >So why can't you do this:
  25. >
  26. >void f(int& *p)
  27. >{
  28. >    p = 0;
  29. >}
  30. >
  31. >Or do I just have the syntax wrong?
  32.  
  33. Yes, what you have declared is a pointer to a reference to an int, which
  34. doesn't make sense (it would just be the same as a pointer to an int).
  35. Try
  36.  
  37. void f(int* &p) {
  38.     p = 0;
  39. }
  40.  
  41. -- 
  42. Fergus Henderson             fjh@munta.cs.mu.OZ.AU      
  43. This .signature virus is a self-referential statement that is true - but 
  44. you will only be able to consistently believe it if you copy it to your own
  45. .signature file!
  46.