Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yes, as others have said, using an opaque class is preferable to using a void pointer.

class Impl;

This isn't just for hiding, it also gives you faster compilation.



> This isn't just for hiding, it also gives you faster compilation.

That seems unlikely. What are you basing this on?


It means that the header that declares class A doesn't have to #include the header that declares class B, unless B is a part of its public interface. It doesn't sound like much, but the implementation dependency chain can be much longer in practice; and more importantly, all those savings apply to every translation unit that includes the header.


Ah, that's what you meant. Your previous comment reads as if an opaque class results in faster compilation than a void pointer, but those are the same as far as that goes, and you were comparing both to a non-pimpl version.


There might be a few hundred CPU cycles saved in compilation from not having to static cast the void* pointer to the implementation class.


Haha, sure, and the other way around, time is spent constructing the compile-time type info for the pimpl class. Let's ignore both since the impact would be so small it would almost certainly be drowned out by all the random noise that happens all the time.


Yes, I was comparing

class Foo;

to

#include "Foo.h"

and I would not consider using a void pointer for anything other than an allocator.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: