 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Macca Guest
|
Posted: Mon Sep 27, 2004 3:24 pm Post subject: Pointer or Reference |
|
|
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
|
|
| Back to top |
|
 |
John Harrison Guest
|
Posted: Mon Sep 27, 2004 3:28 pm Post subject: Re: Pointer or Reference |
|
|
"Macca" <asbc31 (AT) dial (DOT) pipex.com> wrote
| Quote: | 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
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Mon Sep 27, 2004 3:36 pm Post subject: Re: Pointer or Reference |
|
|
Macca wrote:
| Quote: | 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
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|