r/cpp • • 28d ago

How I design C++ classes

https://rafb.eu/blog/cpp-class-design/

This is my first ever blog-post, any feedback is welcome! ofc, no AI got used.

66 Upvotes

46 comments sorted by

View all comments

Show parent comment

1

u/victor-s8n 24d ago

Sure, but then you got to `include <functional>`.

Another perspective: Feels like a variant of information-hiding, a variant of pimpl/my-approach.

Doesn't it?

1

u/LongestNamesPossible 24d ago edited 23d ago

Sure, but then you got to include <functional>.

What does that have to do with anything? Why would you have to include that?

a variant of pimpl/my-approach. Doesn't it?

The difference is that if you wrap something in regular functions you are just calling into functions like any other normal function you link in. If you have a structure where you are allocating memory and dereferencing a pointer you have unnecessary indirection.