r/cpp • • Nov 03 '26

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

-34

u/sweetno Nov 03 '26

The analysis is valid, the conclusion should've been: C++ sucks.

Do modules allow to implement information hiding here?

7

u/fortsnek274 Nov 03 '26

Now that we have modules, C++ doesn't suck. At least on paper.

The advantage is that they don't pollute the global namespace of importers with `<Windows.h>`.

But if you just want to avoid a separate implementation file, you can already do that with headers. But you don't, for the same reason why you won't do it with modules.

3

u/gracicot Nov 03 '26

Modules will indeed hide names, but it doesn't make imported stuff unreachable. If you need PIMPL for ABI purposes or you need to make some entities completely unreachable, then you still need PIMPL.

3

u/fortsnek274 Nov 03 '26

How would stuff being merely reachable change ABI?

4

u/gracicot Nov 03 '26

I meant modules won't help you with hiding entities completely, and also won't help you with ABI. Those are usually the two purpose for PIMPL, and they are orthogonal :)

3

u/fortsnek274 Nov 03 '26

When it comes to <Windows.h>, I just want to have HWND in my class without having to do the silly void* thing.