beginner's question regarding pass parameter

  • Thread starter Matthew Monopole
  • Start date
M

Matthew Monopole

pass by value is:
declare with:
function(class a)
call with:
function(a)
and a is COPIED

pass by reference is
declare with:
function(class *a)
called with:
function(&a);
and a pointer of a is COPIED, but only one copy of a in memory

pass by (what's the third one???) is:
declare with:
function(class& a);
called with
function(a);
and a pointer is passed, only one copy in memory...

IS THIS CORRECT?
 
J

Jakob Bieling

Matthew Monopole said:
pass by value is:
declare with:
function(class a)
call with:
function(a)
and a is COPIED
Right.

pass by reference is
declare with:
function(class *a)

Actually, this is passing by /pointer/. myclass* is a
pointer-to-myclass.
called with:
function(&a);
and a pointer of a is COPIED, but only one copy of a in memory
Right.

pass by (what's the third one???) is:
declare with:
function(class& a);

This would then be passing by /reference/. myclass& is a
reference-to-myclass.
called with
function(a);
and a pointer is passed, only one copy in memory...

Right.

hth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top