C++ pimpl

so so at so.so
Sun Feb 26 21:48:00 PST 2012


On Sunday, 26 February 2012 at 21:03:11 UTC, Robert Klotzner 
wrote:

> Yeah, I got that. What I don't get is why it needs to be a 
> template?
> Wouldn't a simple base class with a destructor suffice?

Indeed it would suffice. Nothing really special, i didn't want 
pimpl to be a "one true base class" that you could do things like:

vector<pimpl*> v;

> Well my initial example was Qt. Take for example the QWidget 
> class, you
> usually derive from it in order to implement custom widgets and 
> with the
> PIMPL idiom it is ensured that your derived classes will not 
> break upon
> addition of private fields in QWidget. It is a black box, a 
> derived
> class does not have access to private fields.
>
> The whole purpose of my proposal is, to really hide private 
> fields so
> that not just the API is stable, but also the ABI.

I understand. My use case was that i needed an alternative to C 
way of doing it.
I was thinking that C++/D got namespaces, modules, class/struct 
methods. It should be possible to improve C pimpl.

So instead of:
libFun(handle, ...);

You would do:
handle.fun(...);

Now you have a cleaner code, cleaner global namespace with zero 
cost.


More information about the Digitalmars-d mailing list