Created
January 27, 2026 11:16
-
-
Save mrange/9ae4fd1f52e1460274cc1fb06958c02f to your computer and use it in GitHub Desktop.
pimpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "pimpl.h" | |
| int main() { | |
| auto x = new pimpl(); | |
| x->the_method(); | |
| delete x; | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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