Skip to content

Instantly share code, notes, and snippets.

@mrange
Created January 27, 2026 11:16
Show Gist options
  • Select an option

  • Save mrange/9ae4fd1f52e1460274cc1fb06958c02f to your computer and use it in GitHub Desktop.

Select an option

Save mrange/9ae4fd1f52e1460274cc1fb06958c02f to your computer and use it in GitHub Desktop.
pimpl
#include "pimpl.h"
int main() {
auto x = new pimpl();
x->the_method();
delete x;
return 0;
}
#include <cstdio>
#include "pimpl.h"
namespace {
class impl {
public:
void the_method() {
std::printf("Hello\n");
}
};
}
pimpl::pimpl()
: _pimpl(new impl()) {
}
pimpl::~pimpl() {
delete ((impl*)_pimpl);
}
void pimpl::the_method() {
// There are ways to make this shorter but left it simplisitc
((impl*)_pimpl)->the_method();
}
#pragma once
class pimpl {
void * _pimpl;
public:
pimpl();
~pimpl();
void the_method();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment