this post was submitted on 08 Jul 2023
16 points (100.0% liked)
C++
1806 readers
2 users here now
The center for all discussion and news regarding C++.
Rules
- Respect instance rules.
- Don't be a jerk.
- Please keep all posts related to C++.
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
You need pointers to implement low-level stuff or for example containers. Sometimes you really just need the memory address itself e.g. for MMIO. That said, much of the stuff is implemented for you by the standard library and you do not usually need to directly use the pointers. That might change in embedded space.
Shared ownedship is another part where (reference-counted) pointers are useful.
std::shared_ptr
is this. I would generally say that shared ownedship in itself is much harder to reason than non-shared, but there are situations where you really want shared ownership.Pointers in general shouldn't be your go-to tool. They are easy to mess up with, and memory errors are annoying to debug. And in my experience people who are overconfident in their use are the ones writing the worst security holes and incomprehensible interfaces. (Though those overconfident people with their BS keep me in business, so there's that.)
All that said, I wouldn't even teach pointers and raw memory stuff in the C++ intro course if I didn't know it comes up so often in job interviews.