While this should be a trivial question I was unable to find an answer this far. In C APIs there are lots of functions that take pointers and pointers to pointers as arguments. How can I use PROPERLY smart pointers as arguments with C APIs.
Here is an example that I'd like to convert to using std::unique_ptr:
FMOD_SYSTEM* system = nullptr;
result = FMOD_System_Create(&system); // Create the main system object
FMOD_SOUND* musicStream;
result = FMOD_System_CreateSound(system,
musicStreamPath,
FMOD_CREATESTREAM,
nullptr,
&musicStream);
Reference: FMOD_System_Create FMOD_System_CreateSound
I start declaring the smart pointers as:
std::unique_ptr<FMOD_SYSTEM> system = nullptr;
std::unique_ptr<FMOD_SOUND> musicStream = nullptr;
Aucun commentaire:
Enregistrer un commentaire