Why don't we use the pimpl idiom?

Over and over again we find ourselves in situations where we want to add data members to a class without breaking ABI, That can be, and has been, done in an ugly way. See e.g.
and the discussion at the end of https://bugzilla.gnome.org/show_bug.cgi?id=727822#c3.

The pimpl (pointer to implementation) idiom, described at http://en.wikipedia.org/wiki/Pimpl, offers a better solution. In a new class, add

    struct Impl;
    Impl* pimpl;

struct Impl is defined in the .cc file. It's not part of the ABI. It can be changed without breaking ABI.

The drawback of using the pimpl idiom consistently is of course that it requires an extra pointer in each object instance. In many classes, those pointers will never be needed.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]