[openbeos] Re: Pointer or reference?

On Mon, Mar 29, 2004 at 11:40:33AM -0500, Scott MacMaster wrote:

> classes are string and list classes.  The other place are in designs that
> use polymorphism.

You can do polymorphism with references too (they really are just syntactically
cleaner pointers). In some cases it's easier to use pointers, for example
dynamic_cast with a reference will throw an exception if the type doesn't
match, rather than returning NULL like dynamic_cast on a pointer will. But if
all you're doing is passing around 'const Some_base_class*' to get
polymorphism, 'const Some_base_class&' works just as well and is nicer to read
(IMO).

-J

Other related posts: