Each class should have exactly one member variable called 'd'. d shall be a pointer to a class named ClassNamePrivate. For example:
// HSSRenderer.h
class HSSRendererPrivate;
class HSSRenderer
{
public:
HSSRenderer();
~HSSRenderer();
int doSomething() const;
private:
HSSRendererPrivate * const d; // const so we can't change what 'd' points to - this is desired in most cases
};
// HSSRenderer.cpp
class HSSRendererPrivate
{
public: // public to HSSRenderer, but private to everything else in practice since the class itself is only defined in the .cpp
HSSRendererPrivate() : member1(), member2(), member3() // always use initializer lists
int member1;
int member2;
int member3;
};
HSSRenderer::HSSRenderer() : d(new HSSRendererPrivate())
{
}
HSSRenderer::~HSSRenderer()
{
delete d;
}
int HSSRenderer::doSomething() const
{
// access to all of HSSRenderer's pseudo member variables is done through the d pointer
return d->member1;
}
Make sure that clone() methods copy the actual members of the *Private class; never just copy the pointer over
Although AXR's convention is to always use this-> to reference class members, the d pointer itself should be an exception to this rule
Each class should have exactly one member variable called 'd'. d shall be a pointer to a class named ClassNamePrivate. For example:
this->
to reference class members, the d pointer itself should be an exception to this rulehttp://en.wikipedia.org/wiki/Pimpl#C.2B.2B http://techbase.kde.org/Policies/Binary_Compatibility_Issues_With_C++#Using_a_d-Pointer http://qt-project.org/wiki/Dpointer http://zchydem.enume.net/2010/01/19/qt-howto-private-classes-and-d-pointers/