Take the 2-minute tour ×

I bet this has probably been asked before, but since reference (int& name) is taken the same as reference counting by searchers, couldn't find a single thing.

Why isn't there ever mention of references as alternates to smart pointers? Is it just for the null case, or is there something else? What advantages/disadvantages are there to using either?

share|improve this question
To the random drive-by downvoter: That was rude. No comment? Don't down vote without a comment, and don't down vote things that seem like dumb questions to you. The questioner is confused between references, reference counts, and other things. We were all novices at once. Instead of down-voting a dumb question, provide an answer. I'm up-voting just to offset the stupid down-vote. –  David Hammen Aug 25 '12 at 7:30
add comment

1 Answer

up vote 5 down vote accepted

I think you have your terminology mixed up. A reference and the term reference counting aren't really talking about the same thing.

References and smart pointers, or even pointers for that matter are very different and not interchangeable.

A reference cannot be reseated. Meaning that once you have a reference, it can only refer to the thing it initially referred to. A reference is merely a memory address.

A pointer on the other hand, points to a memory address; it can be changed to point to different memory addresses.

When someone says a smart pointer does reference counting, they mean the smart pointer is keeping count of how many objects are referring to the memory the smart pointer is pointing at. This is different from a reference.

I hope that helps.

share|improve this answer
I know well that reference and reference counting aren't the same. It's the searchers, like Google and the one here, who can't see the difference (context) and show me sites that relate to reference counting and smart pointers, instead of reference and smart pointers –  efaj Aug 25 '12 at 6:28
But, I didn't know references couldn't be switched/swapped or made to reference something else. Now with that... it's obvious why they don't replace smart pointers. –  efaj Aug 25 '12 at 6:32
add comment

Your Answer


