Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@willol You have a class with which you interact with public member functions. You need to define the class in a header file, which you publish for other files to use. But since you need to declare every member of the class right there, you need to show the private and protected members to the world.
Ideally I would like to publish only the public parts in the header file (exposing only what needs to be exposed), and hiding the private and protected in the cop file. -
@Christos needs forward declaration, memory allocation... But maybe the least inelegant ;)
-
@Christos well in C you're forced to do OO with explicit pointers and anonymous struct, so you're less tempted to show private parts.
It's the same as the opaque pointer thing in C++, but pointers are not very C++y (anymore), you need to deal with memory allocation which isn't very C++y anymore either, and you need to refer to these private parts through another object in the implementation.
I find it OK in C, because that's how C is, pointery. I find it inelegant in C++ because it's less and less pointers. It feels like C with C++ syntax.
Related Rants
Annoyance with C++: no elegant way to hide private members of a class while exposing its API.
undefined
wk30