|
-
May 14th, 1999, 07:46 AM
#1
to pass an object by reference or to pass a pointer to the object
Hi,
I am having difficulty choosing between whether to pass an object by reference or to pass a pointer to it to a function. This is a generic question, not related to any particular class. Basically, if you want a function ro receive the address of an object, which option is preferable ?
I'm aware of a few considerations :
1 A pointer can have a null value. If the function declares a pointer parameter, the caller can pass in a NULL, and the function can test for it; with a reference parameter, the caller must specify an object.
2 If the function returns a pointer, it can return NULL, and the caller can test for it, with a reference return, the function must return an object.
3 One advantage of using a reference is that you won't be passed a NULL pointer. And so there’s no need to test for one.
4 Another advantage would be in easier coding of the called function, i.e. you don't have to dereference the pointer.
Regards,
Brendan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|