Hi,
lately I make myself familiar with the PIMPL idiom. And all examples do in the private declaration something like this:
#define PIMPL_DECLARE_PRIVATE(Class) \
private: \
inline Class##Private* d_func() {return reinterpret_cast<Class##Private*>(dPtr);} \
inline const Class##Private* d_func() const {return reinterpret_cast<const Class##Private*>(dPtr);} \
void* dPtr;
#define PIMPL_DECLARE_PRIVATE(Class) \
private: \
inline Class##Private* d_func() {return reinterpret_cast<Class##Private*>(dPtr);} \
inline const Class##Private* d_func() const {return reinterpret_cast<const Class##Private*>(dPtr);} \
void* dPtr;
To copy to clipboard, switch view to plain text mode
And assuming that you only work with normal classes: Why they all use reinterpret_cast? I don't see the need even if reinterpret_cast is cheap. What's wrong with:
#define PIMPL_DECLARE_PRIVATE(Class) \
private: \
inline Class##Private* d_func() {return dPtr;} \
inline const Class##Private* d_func() const {return const_cast<const Class##Private*>(dPtr);} \
Class##Private* dPtr;
#define PIMPL_DECLARE_PRIVATE(Class) \
private: \
inline Class##Private* d_func() {return dPtr;} \
inline const Class##Private* d_func() const {return const_cast<const Class##Private*>(dPtr);} \
Class##Private* dPtr;
To copy to clipboard, switch view to plain text mode
Do I miss something important here?
Bookmarks