C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Pointer or Reference

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Macca
Guest





PostPosted: Mon Sep 27, 2004 3:24 pm    Post subject: Pointer or Reference Reply with 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


Back to top
John Harrison
Guest





PostPosted: Mon Sep 27, 2004 3:28 pm    Post subject: Re: Pointer or Reference Reply with quote




"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





PostPosted: Mon Sep 27, 2004 3:36 pm    Post subject: Re: Pointer or Reference Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.