| 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.
.
|
|
|
|

|
Related Articles |
|
|