D
Dave Rahardja
Let's compare your example to the "wrapper"-method:
extern "C" void OpenResource();
extern "C" void CloseResource();
/* ... */
class CResource
{
public:
CResource() { OpenResource(); }
~CResource(){ CloseResource(); }
}
void fn()
{
CResource r;
ExceptionThrowingCPPFunction();
}
Writing that one wrapper class once certainly seemed to pay off. Also,
the wrapper solution is reusable - available everywhere you use the
CResource.
Oh, I know. The example I gave was a trivial one. Some of the libraries I've
used have dozens of functions to manipulate some internal state, and must be
encapsulated by the dozen, which is a pain.
But you're right that once we do it we can reuse it for the next go-round.
-dr