gwaters@bwdls35.bnr.ca (Glenn Waters) (10/01/90)
I have a variable that is declared: char *x; I want to call a function saying: f(x); How do I declare the function, such that x comes in as a reference var. I tried a few different ways, to no avail... f( char * &xr )... f( char & *xr ) <-- I thought this should really work. Glenn Waters, Network Systems Support gwaters@bnr.ca Bell-Northern Research, Ltd. ...!uunet!bcars192!gwaters P.O. Box 3511, Station C (613)763-3933 (Voice) Ottawa Ontario Canada K1Y 4H7 (613)763-3283 (FAX) #include <disclaimer.h>
steve@taumet.com (Stephen Clamage) (10/02/90)
gwaters@bwdls35.bnr.ca (Glenn Waters) writes: >I have a variable that is declared: > char *x; >I want to call a function saying: > f(x); >How do I declare the function, such that x comes in as a reference var. >I tried a few different ways, to no avail... 1. > f( char * &xr )... 2. > f( char & *xr ) <-- I thought this should really work. No, your example 2 would mean "xr is a pointer to a char reference". Your example 1 is what you want, is legal, and should work -- "xr is a reference to a char*". It does work on two compilers I tried, Oregon C++ and Turbo C++. It sounds like the compiler you are using needs fixing. (Or maybe there is an error in your coding which doesn't show in this question.) -- Steve Clamage, TauMetric Corp, steve@taumet.com
ericg@ucschu.ucsc.edu (Eric Goodman) (10/09/90)
In article <1990Oct1.163755.20207@bnrgate.bnr.ca> gwaters@bwdls35.bnr.ca (Glenn Waters) writes: > I have a variable that is declared: > char *x; > I want to call a function saying: > f(x); > How do I declare the function, such that x comes in as a reference var. As said in another response, you can't have a pointer to a reference. It's possible to get a reference to the *pointer* using this scheme. If you want to get a reference to the dereferenced pointer, you need to dereference it yourself: f(char &xr)... main(){ f(*x); } Eric Goodman, UC Santa Cruz ericg@ucschu.ucsc.edu ericg@ucschu.bitnet