So when trying to get in touch with the PIMPL
idiom one finds two common ways of doing it:
Using forward declaration outside a class:
class PimplClass; class VisibleClass { private: PimplClass* d_ptr; };
Using forward declaration inside a class:
// *.hpp class VisibleClass { private: struct PimplClass; PimplClass* d_ptr; }; // *.cpp file: struct VisibleClass::PimplClass { int x; };
Two questions here:
- To be honest I have no idea why the second one works. I mean the expression struct PimplClass I only do know from forward declaration but not within a class. Can someone please explain this to me?
- Which solution to use? Where are the advantages or is it jsut a matter of taste?