// In C++, when anything in a class definition changes (even private members),
// all users of that class must be recompiled. To reduce these dependencies,
// a common technique is to use an opaque pointer to hide some of the implementation details.
class X
{
public:
/* ... public members ... */
protected:
/* ... protected members? ... */
private:
/* ... private members? ... */
struct XImpl;
XImpl* pimpl_; // opaque pointer to
// forward-declared class
};
// The questions for you to answer are:
// What should go into XImpl? There are four common disciplines.
// 1.Put all private data (but not functions) into XImpl.
// 2.Put all private members into XImpl.
// 3.Put all private and protected members into XImpl.
// 4.Make XImpl entirely the class that X would have been,
// and write X as only the public interface made up entirely of simple forwarding functions (a handle/body variant).
// What are the advantages/drawbacks of each? How would you choose among them?
// Does XImpl require a pointer back to the X object?
// Option 1 (Score: 6 / 10): Put all private data (but not functions) into XImpl.
// Option 2 (Score: 10 / 10): Put all nonvirtual private members into XImpl.
// Virtual functions should normally be private,
compilation firewalls
最新推荐文章于 2023-08-27 09:09:11 发布