Created
July 14, 2014 20:21
-
-
Save dwilliamson/8f35212fe81b097b3b50 to your computer and use it in GitHub Desktop.
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
namespace api | |
{ | |
namespace blah | |
{ | |
// Opaque handle to the type this namespace exposes functions for | |
struct Blah; | |
// Lifetime management (malloc/free with construct/destruct) | |
Blah* New(u32 param); | |
void Delete(Blah* blah); | |
// 'Blah' API | |
void DoSomething(Blah* blah, u32 param); | |
u32 GetSomething(const Blah* blah); | |
} | |
// Bring the opaque handle into the API namespace | |
using blah::Blah; | |
} |
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
#include "Blah.h" | |
int main() | |
{ | |
api::Blah* blah = api::blah::New(2); | |
// All remaining work can be done with Koenig Lookup (ADR) | |
DoSomething(blah, 1); | |
u32 x = GetSomething(blah); | |
Delete(blah); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment