A pointer to an implementation is the use of a pointer to another class as a private member in one class. The benefits of this approach:

  • Binary compatibility
  • Data hiding
  • Reduce recompilation units


Here’s an example:

#include <iostream>

class out {
    class in;
	in *m_in;
    
  public:
    out(int a); 
};

class out::in {
    int m_a;

  public:
    in(int a) : m_a(a) {}
    void show(void) { std: :cout << "m_a: " << m_a << std: :endl; }}; out::out(int a): m_in(new out::in(a)) {}

int main(void) {
    out o(1);
}
Copy the code