home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
- From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
- Subject: Re: Reference to a pointer??
- Message-ID: <9225519.23036@mulga.cs.mu.OZ.AU>
- Keywords: pointer, reference
- Sender: news@cs.mu.OZ.AU
- Organization: Computer Science, University of Melbourne, Australia
- References: <ucosmo.716157377@mcl>
- Date: Fri, 11 Sep 1992 09:20:45 GMT
- Lines: 33
-
- 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?
-
- Yes, what you have declared is a pointer to a reference to an int, which
- doesn't make sense (it would just be the same as a pointer to an int).
- Try
-
- void f(int* &p) {
- p = 0;
- }
-
- --
- Fergus Henderson fjh@munta.cs.mu.OZ.AU
- This .signature virus is a self-referential statement that is true - but
- you will only be able to consistently believe it if you copy it to your own
- .signature file!
-