Should I use pointers all the time in C++?

shubham
2 min readNov 16, 2021

Contrary to most answers here, I have no particular aversion to pointer implementations in C++.

To me, a pointer is just a variable. So saying ‘pointers are bad’ is saying variables are bad. After all it is really just an unsigned integer that contains an address and has a type associated with it.

An indirect reference serves a purpose. It allows access without copying and replacing values and allows objects to cross context boundaries. Of course the possibility of abuse and error is present in such situations, but it always is anyway really. Any variable can contain a bad value, be it a pointer or a direct variable.

C++ has some tricks up its sleeve with references, lvalue references, smart casting, etc, that do indeed make for safer code constructs when indirection and pass-by-reference is used — which is all the time. Of course it is encouraged to use these tools to write more robust and reusable code.

But it is not altogether possible to avoid pointer implementations in a lot of situations, so to be ‘afraid’ or revulsed by them is to throw away some essential programming tools.

Look into the STL and you will find a lot of pointer stuff in there.

Almost any time you need to interface with C code you are going to be passing pointers around. You have to; that’s how C operates on anything more complicated than a primitive value.

READ MORE:

--

--