TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: MICHAEL MCGAVIN
from: ADAM MAJER
date: 1998-03-24 16:25:00
subject: passing by reference

MM>void afunction(int &var1)
MM>{
MM>  var1=546;
MM>}
MM>void main()
MM>{
MM>  int k;
MM>  afunction(k);
MM>}
MM>ie. An integer variable can just be passed to it ordinarily.  This is 
really
MM>confusing me.  :-)  I hate trying to work out where pointers are going and
MM>stuff but by my logic so far, '&var1' would be an integer and so 'var1' 
woul
MM>be a junk value pointed to by whatever was currently in the integer.
MM>Is it just me who's having a hell of a time thinking this through or is 
this
MM>some sort of exception in the design of the language whereby a '&' 
character
MM>can be used to get the compiler to automagically work out all the pointer
MM>stuff?  :-]
That's the way I understand referencing stuff. The compiler takes care
of the pointers. It's good for pointer's to pointers stuff - you can't
make a mistake.
        int **r1; <- points somewhere
        int &*r2; <- reference to a pointer.
when you assign a value to r2, it must be a pointer where as the pointer
can also be assigned to r1 and *r1. This could lead to problems.
 * SLMR 2.1a * We all livein a yellow subroutine.
--- FMail 0.92
---------------
* Origin: The Programmer's Oasis on FIDONET! (1:348/203)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.