Skip to content

Instantly share code, notes, and snippets.

@dwilliamson
Last active May 12, 2017 16:10
Show Gist options
  • Save dwilliamson/a47cc8b4ed02e9daef685433baabd322 to your computer and use it in GitHub Desktop.
Save dwilliamson/a47cc8b4ed02e9daef685433baabd322 to your computer and use it in GitHub Desktop.
How I Pimpl
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);
}
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