Post Reply 
need help with c++
Author Message
u_c_taker
hacks=drama

Posts: 3,185.2011
Threads: 102
Joined: 29th Jan 2007
Reputation: -1.03084
E-Pigs: 36.7855
Offline
Post: #1
need help with c++
i was just learning c++ but i didnt understand the concept of function calling by name and by reference could anyone give me breif description or a link to a good c++ guide

19/04/2007 09:58 AM
Find all posts by this user Quote this message in a reply
_VEndeTta
Endless Night

Posts: 522.1732
Threads: 48
Joined: 9th Apr 2007
Reputation: -3.19624
E-Pigs: 4.8849
Offline
Post: #2
RE: need help with c++
When you Pass by Name your function simply copies the values you pass
into different variables and uses those for calculations, your original values/data
will always remain untouched because your function is using only the copies.

When you Pass by Reference the function will use the actual data you pass in,
so any changes made to them during the function will remain for the rest of the program.

i.e.

void blah(int A)
{
A = 5000
}

void blah2(int &A)
{
A = 5000
}

the second will result in A being set equal to 5000,
the first will result in nothing. It will copy A, set that
copy equal to 5000 and then exit.

Fore example,

Code:
1
2
3
4
5
6
7
8
9
int Rawr = 80;

blah(Rawr);
cout << Rawr;
//Would display 80

blah2(Rawr);
cout << Rawr;
//Would display 5000


[Image: 3c68ce3.jpg]
And when you gaze long into an abyss,
the abyss gazes also into you.
(This post was last modified: 19/04/2007 10:40 AM by _VEndeTta.)
19/04/2007 10:33 AM
Find all posts by this user Quote this message in a reply
u_c_taker
hacks=drama

Posts: 3,185.2011
Threads: 102
Joined: 29th Jan 2007
Reputation: -1.03084
E-Pigs: 36.7855
Offline
Post: #3
RE: need help with c++
yeah thanks its more clear now

20/04/2007 09:49 AM
Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)

 Quick Theme: