TIP: Click on subject to list as thread! ANSI
echo: nthelp
to: Antti Kurenniemi
from: John Beckett
date: 2004-11-10 08:40:16
subject: Re: C++

From: John Beckett 

"Antti Kurenniemi"  wrote in
message news::
> But when you pass that "d" to a function, you're passing a
"pointer"
> (reference? handle? what do you call it now?) to that object and *not*
> creating another object in the scope of the function that was called, right?

Paul covered all the possibilities. I will just add that if you have:

void func1(Date d)
{
     // ...
}

then call the above with something like:
    Date a;
    func1(a);

the result is that the variable a is copied to the argument d (using the
copy constructor of Date). So, passing an int and passing a Date are
conceptually identical.

Since the above is usually inefficient, it is common for the function to be
defined in the alternative way shown below:

void func2(Date &d)
{
    // ...
}

The call to func2 looks exactly like a call to func1, i.e. func2(a).

However, func2(a) actually passes a reference to a (which is physically
identical with a pointer to a). The fact that this is common is probably
why you said what you did earlier.

John

--- BBBS/NT v4.01 Flag-5
* Origin: Barktopia BBS Site http://HarborWebs.com:8081 (1:379/45)
SEEN-BY: 633/267 270 5030/786
@PATH: 379/45 1 396/45 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

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™.