Quote:Original post by Oluseyi
Quote:Original post by F-Kop
Another thing that I often see questions about is hiding private members of classes. If there is no header to read, then all members are hidden. The only downfall to this is that documentation becomes more of a necessity for libraries that don't include source code.
You can ship C++ headers that exclude private members. They just provide interface declarations, after all.
Yep. You can do it in several ways, too.
1) Simply compile your code, then erase the private members from the header. Ship the modified header and the object file. This assumes that your intent is to provide a closed-source library.
2) Similarly, use the preprocessor:
foo.h
#ifndef FOO_H#define FOO_Hclass Foo { #include "foo_internals.inl" public: // blahblahblah};#endif
foo_internals.inl
int spam; float quux; // etc.
3) If your intent is to provide open source but simply avoid long compile times in development (due to constantly changing the header to add or remove private data), use the pImpl idiom. If you want polymorphic behaviour anyway, you can get the pImpl benefits for free: just make the "public" class be a wrapper that delegates to a polymorphic "implementation" class that is held by pointer (as the sole private member of the wrapper). To get the right copy semantics for the wrapper, just use the_edd's value_ptr (an idea I independently came up with, but didn't develop nearly as far).