View Full Version : Omitting private part of a class definition

8th March 2007, 16:19
Just a quick question.

Can you omit the private part of a class definition (inside the header files) when you distribute them together with a library for other users ? It seems to link and run fine, but I would like to be sure there are no issues. It would be ideal for me since I would like to hide the implementation details as much as possible.

8th March 2007, 16:41
In the general case you cannot. The problem is that the private parts of the class might be (and probably are) used to calculate the memory layout, thus if that is empty you will get into serious problem eventually.

Another problem is that even private member functions might be exported, and thus might produce problems when they are not declared.

My suggestion would be to follow the pimpl idiom (http://www.gotw.ca/gotw/028.htm) to hide implementation detail. Check for example the Qt sources; you will find many "d-pointers" (http://techbase.kde.org/Policies/Binary_Compatibility_Issues_With_C++#Using_a_d-Pointer), which follows the same principle.

23rd March 2007, 11:51
But you can just wrap/facade you class in a class that only calls the public members of your class - if that helps.