[Q] when to use pointer and when to use reference?



 DEVELOP > c-Plus-Plus > [Q] when to use pointer and when to use reference?

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Yuming Ma"
Date: 25 Nov 2003 12:24:52 PM
Object: [Q] when to use pointer and when to use reference?
this is an interview question.
thanks,
ym,
.

User: "Mike Wahler"

Title: Re: [Q] when to use pointer and when to use reference? 25 Nov 2003 12:26:40 PM
"Yuming Ma" <ma_yuming@yahoo.com> wrote in message
news:Pine.OSX.4.58.0311251323480.4237@home2.local...

this is an interview question.

This is an opinion:
Use a reference by default, only use a pointer with
compelling reason.
-Mike
.

User: "Ron Natalie"

Title: Re: [Q] when to use pointer and when to use reference? 25 Nov 2003 12:27:00 PM
"Yuming Ma" <ma_yuming@yahoo.com> wrote in message news:Pine.OSX.4.58.0311251323480.4237@home2.local...

this is an interview question.

You're not going to get that job.
.

User: "Eric"

Title: Re: [Q] when to use pointer and when to use reference? 25 Nov 2003 12:43:35 PM
Yuming Ma <ma_yuming@yahoo.com> wrote:

this is an interview question.

I tend to use a reference by default.
However, for example, when it is useful to be able to check to see if a
parameter is NULL to help determine how a function behaves, then I will
use a pointer.
--
== Eric Gorr ========= http://www.ericgorr.net ========= ICQ:9293199 ===
"Therefore the considerations of the intelligent always include both
benefit and harm." - Sun Tzu
== Insults, like violence, are the last refuge of the incompetent... ===
.

User: "lilburne"

Title: Re: [Q] when to use pointer and when to use reference? 25 Nov 2003 02:59:37 PM
Yuming Ma wrote:

this is an interview question.

Depends on context of the question.
Mainly if the reference needs to be 'reassigned' use a pointer.
Then there are style issues. For example some styles would
have you use a const reference for input parameters to a
function and a non-const pointer for output parameters.
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER