Last active
May 12, 2017 16:10
-
-
Save dwilliamson/a47cc8b4ed02e9daef685433baabd322 to your computer and use it in GitHub Desktop.
How I Pimpl
This file contains 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
struct Data | |
{ | |
Data() | |
{ | |
} | |
~Data() | |
{ | |
} | |
// NO methods - this is a pure data type | |
// List of properties | |
int x; | |
void* resource; | |
}; | |
// Local static for all implementation details | |
namespace | |
{ | |
// This would normally have to be in your class private section | |
void Detail(Data* data) | |
{ | |
} | |
} | |
// Limited boiler-plate | |
API::API() | |
{ | |
data = new Data(); | |
} | |
API::~API() | |
{ | |
delete data; | |
} | |
void API::DoStuff() | |
{ | |
// Write most of the implementation in here, branching out to local statics | |
// for any further detail implementations | |
data->resource; | |
data->x; | |
// Chain to other functions | |
Detail(data); | |
} |
This file contains 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
class API | |
{ | |
public: | |
// Use new/delete to control lifetime | |
API(); | |
~API(); | |
void DoStuff(); | |
private: | |
struct Data* data; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment