Is it wrong to dereference a pointer to get a reference?

Viewed 16251

I'd much prefer to use references everywhere but the moment you use an STL container you have to use pointers unless you really want to pass complex types by value. And I feel dirty converting back to a reference, it just seems wrong.

Is it?

To clarify...

MyType *pObj = ...
MyType &obj = *pObj;

Isn't this 'dirty', since you can (even if only in theory since you'd check it first) dereference a NULL pointer?

EDIT: Oh, and you don't know if the objects were dynamically created or not.

7 Answers
Related