this post was submitted on 08 Jul 2023
16 points (100.0% liked)
C++
1766 readers
1 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 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Hi OP, pointers are very powerful. You’ve already seen some responses to your question about why/when to use it, but there’s another cool trick I like to do with pointers. Namely, data hiding with opaque pointers (an application of type erasure). Especially in library code where I don’t want to introduce too many includes in the consuming application, I will hide data and implementation using the pimpl idiom. Another great use case for pointers.
https://en.cppreference.com/w/cpp/language/pimpl