Skip to content

Instantly share code, notes, and snippets.

@micw
Last active September 3, 2024 12:02
Show Gist options
  • Save micw/f03e01914d416cfa04709b1071ece1ed to your computer and use it in GitHub Desktop.
Save micw/f03e01914d416cfa04709b1071ece1ed to your computer and use it in GitHub Desktop.
C++ Public/Private API separation

api.h

class PubApi {
  public:
    virtual void doSomething() = 0;
    static PubApi* Instance;
}

impl.h

#include "api.h"
class Impl: public PubApi {
  private:
    void doSomethingPrivately();
}

impl.c

#include "impl.h"
PubApi* PubApi::Instance = new Impl();
void PubApi::doSomething() {
  doSomethingPrivately();
}
void PubApi::doSomethingPrivately() {
  // TODO
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment