2

to ensure the ABI with the pimpl pattern, is that true that we only need to put all the data members to the "Private class" ? I see in some introduction about pimpl, they also make all the functions implementations in the "Private class" and define a "wrapper function" on the exported class for each function in the "Private class", is that necessary?

1
  • I assume the previous ABI already is using pimpl so you already have a pointer for your private implementation. Commented Apr 15, 2014 at 15:40

2 Answers 2

2

When your aim is to have ABI compatibility, then you need to put all data member variables in the private class.

There is this famous article about c++ ABI compatibility. From their to do's/don'ts :

  • you can not change the signature of existing member functions. You can add new methods
  • you can not add virtual functions to a class without one
  • you can not add or change non-static data members, or change their order

The list goes on, but these 3 items should cover your questions.

As long as you are 100% sure you are not going to modify private member functions, it is fine. If you expect a change, move them to a private class. I always expect a change.

Sign up to request clarification or add additional context in comments.

Comments

1

The advantage of wrapping the functions is that then the functions can be defined in the "private" aka "implementation" class. (Although I always use a struct. Since the entire thing is private to one file I don't see the point to protecting its implementation.)

Since the functions are defined in the same class as the data, you don't need to stick p-> on the front of every access like p->variable.

If you put data in the implementation class/struct but no functions, then all of your function definitions need to put that p-> before every access.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.