views:

195

answers:

2

Possible Duplicate:
When pass-by-pointer is preferred to pass-by-reference in C++?

Hello everyone,

What do you consider a better programming practice: passing objects as pointers or references to functions.
What do you do for input validation?

Thanks.

+4  A: 

It is better C++ style to use a reference. One advantage to this, as I believe you were implying, is that when passing by reference, you no longer need to verify that it is non-null, since references cannot be null. Also, I should add that if you are not modifying the parameter, then you should pass by constant reference. (For primitives or small non-polymorphic objects, you can also pass by value if you aren't modifying it).

Michael Aaron Safyan
+1  A: 

Probably go with references, 'cuz they're cleaner. With pointers, you have a very awkward syntax.

As for validation, I would just do an ASSERT.

George Edison
Do you mean debug assertions or something like boost static assertions?
Andrew
Debug assertions.
George Edison