T
Travis Spencer
Hello,
I am trying to expose a C++ class to C clients using a C-compatible wrapper
API. While doing so, I hit a little snag. When a C client deletes one on my
classes using the provided delete method, shouldn't the pointer that passed
to DeleteFoo be null when returned?
A simplified example of my project follows.
Thanks a lot and enjoy the rest of the weekend.
Regards,
Travis Spencer
Portland, OR. USA
#include <iostream>
typedef void* FOO_HANDLE;
void DeleteFoo(FOO_HANDLE f);
class Foo { /* Compiler generated ctor and dtor */ };
int main(int argc, char** argv)
{
// Foos are normally created by C clients using my CreateFoo API
// function, but this is just a demo.
FOO_HANDLE f = new Foo;
DeleteFoo(f);
if (f != NULL)
std::cerr << "f != NULL. Darn!" << std::endl;
else
std::cout << "f == NULL. Cool!" << std::endl;
}
void DeleteFoo(FOO_HANDLE f)
{
delete static_cast<Foo*>(f);
f = NULL;
}
I am trying to expose a C++ class to C clients using a C-compatible wrapper
API. While doing so, I hit a little snag. When a C client deletes one on my
classes using the provided delete method, shouldn't the pointer that passed
to DeleteFoo be null when returned?
A simplified example of my project follows.
Thanks a lot and enjoy the rest of the weekend.
Regards,
Travis Spencer
Portland, OR. USA
#include <iostream>
typedef void* FOO_HANDLE;
void DeleteFoo(FOO_HANDLE f);
class Foo { /* Compiler generated ctor and dtor */ };
int main(int argc, char** argv)
{
// Foos are normally created by C clients using my CreateFoo API
// function, but this is just a demo.
FOO_HANDLE f = new Foo;
DeleteFoo(f);
if (f != NULL)
std::cerr << "f != NULL. Darn!" << std::endl;
else
std::cout << "f == NULL. Cool!" << std::endl;
}
void DeleteFoo(FOO_HANDLE f)
{
delete static_cast<Foo*>(f);
f = NULL;
}