Martin Steen wrote:
>
You can make a C++ "wrapper" for the C-functions. Example:
// The C-function
// Use "static" to make the C-functions invisible for
// the global scope.
static int FunctionA(int x, int y)
{
return x + y;
}
// the wrapper class
class CWrapper
{
public:
int CallCFunctionA(int x, int y);
};
// implementation of CallCFunctionA
int CWrapper::CallCFunctionA(int x, int y);
{
return FunctionA(x, y);
}
If a C API is written with function to create a pointer to something, a
set of functions to manipulate the pointer and a function to dispose of
it, then it is a good candidate for a C++ wrapper.
pthread_mutex is an obvious example, although it gets tricky when
Condition Variables get into the picture. Note that the mutex lock is a
different object (class) to the mutex itself. I usually make it a
nested class but it doesn't have to be.