TIP: Click on subject to list as thread! ANSI
echo: nthelp
to: Paul Ranson
from: Antti Kurenniemi
date: 2004-11-09 23:04:54
subject: Re: C++

From: "Antti Kurenniemi" 

Thanks Paul. Been too long since I did C++ I see 


Antti Kurenniemi
(or maybe not long enough )

"Paul Ranson"  wrote in message
news:4190ff3b{at}w3.nls.net... You can pass objects by value or by reference,
the behaviour is consistent.

class Date ;

bool DoDate ( Date d )
{
// d is passed by value, DoDate has its own copy.
}

bool DoDate ( Date& d )
{
// d is a reference to the caller's Date object. DoDate may change the
callers object.
}

bool DoDate ( const Date& d )
{
// d is a reference to the caller's Date object. DoDate may NOT change the
callers object.
}

bool DoDate ( Date * pd )
{
// pd is a pointer to the caller's Date object. DoDate may change the
caller's object.
}

bool DoDate ( const Date * pd )
{
// pd is a pointer to the caller's Date object. DoDate may NOT change the
caller's object.
}

It can be inefficient to pass objects by value, in effect a temporary copy
is made which only exists for the life of the function call.  So in that
case use a const reference.

Paul

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