Pointer or Reference

M

Macca

Hi,

I am looking to pass a Structure to a function. I was wondering what the
most efficent way of doing this was, by pointer or by reference?

Thanks In Advance
Macca
 
J

John Harrison

Macca said:
Hi,

I am looking to pass a Structure to a function. I was wondering what the
most efficent way of doing this was, by pointer or by reference?

Thanks In Advance
Macca

They are likely to be equally efficient.

It's a bogus question to ask in any case because you should be concentrating
on the meaning of your code, not micro-efficiency. Which is more meaningful
to use, a pointer or a reference? For instance if you want sometimes to pass
NULL then you should use a pointer since you cannot have a NULL reference.
But in general I would say a reference is the more meaningful choice.

john
 
V

Victor Bazarov

Macca said:
I am looking to pass a Structure to a function. I was wondering what the
most efficent way of doing this was, by pointer or by reference?

In most cases there is no difference in efficiency. As to the
semantics, you need to decide whether it would be possible to have
"no object" situation. If so, pass a pointer, and passing a null
pointer will indicate "no object". If your function cannot work
in a situation when no object is given, then pass by reference.

V
 

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
474,176
Messages
2,570,947
Members
47,501
Latest member
Ledmyplace

Latest Threads

Top