Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Differences bet...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 43928 of 48417
Post > Topic >>

Differences between these three signatures....

by xz <zhang.xi.cn@[EMAIL PROTECTED] > Mar 15, 2008 at 10:18 AM

I just wanna confirm my understanding about the differences between
the signatures as follows, which are called all in the same way:

void foo(Vertex a, Vertex b, Vertex c);
void foo(Vertex & a, Vertex & b, Vertex & c);
void foo(const Vertex & a, const Vertex & b, const Vertex & c);

In the first one, the function actually works on the local copies of
a, b and c. Whatever happens inside foo does not change anything in
the outside world.

In the second one, the function operates on the original copies of a,
b and c. Whatever foo does to a, b and c inside the function
immediately applies on the a, b and c in the outside world.

In the third one, the function operates on the original copies of a, b
and c. However it cannot change anything about a, b or c.

Is that always true, no matter how the copy-constructor of Vertex is
defined?

Basically, people use the first way when they need to only locally
change something of a, b, c but do not want that change influence the
original a, b, and c in the outside world.

People use the second way when they do want the changes to a, b, and c
apply to the original a, b, and c in the outside world. In this case,
a, b, c are actually like returned result.

People use the third way when they don't need to change anything about
a, b, and c in the function, i.e. they only read a, b, and c, and
meanwhile, they want to promote the memory-efficiency.

Is that understanding correct?
 




 5 Posts in Topic:
Differences between these three signatures....
xz <zhang.xi.cn@[EMAIL  2008-03-15 10:18:44 
Re: Differences between these three signatures....
rpgfan3233 <rpgfan3233  2008-03-15 10:37:32 
Re: Differences between these three signatures....
Neelesh Bodas <neelesh  2008-03-15 10:41:53 
Re: Differences between these three signatures....
Paavo Helde <nobody@[E  2008-03-15 14:59:17 
Re: Differences between these three signatures....
James Kanze <james.kan  2008-03-16 03:27:16 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 9:52:08 CST 2008.