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

It (using a void pointer) is a worse way of doing PIMPL. Give the class a name, but don't expose its implementation (use an opaque class). This means that within the file or files that have access to the full implementation the correct type is present and no casts are needed.

Well, what if the actual class is a template? No matter, you can derive a class from a template, as in:

header: class Impl;

implementation:

class Impl: public std::vector<SomeType> { ... };

People who don't do this and use void* wind up with an implementation that has lots of casts in it, and it's easier to introduce bugs, especially once you get to the point where you have two or more hidden implementations.



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

Search: