What are the pros and cons of using d-pointers?
问题 d-pointers are heavily used in Qt, they are an implementation of pimpl idiom. I know advantages and disadvantages of pimpl idiom. But I have missed the advantages of d-pointers implementation. Here and here are the samples of d-pointers. Isn't it easier to just use this? class MyClassPrivate; class MyClass { // interface methods private: MyClassPrivate *pimpl_; }; 回答1: The set of macros for d-pointer pattern provides some sort convenience and consistencies. For example, Q_DECLARE_PRIVATE