Listing 1: C++ wrapper on C
struct C_structure
{
/* ... */
};
class C_wrapper
{
public:
C_wrapper()
{
// ...
tag_ = new_called_;
new_called_ = false;
}
~C_wrapper()
{
// ...
}
operator C_structure &()
{
return value_;
}
operator C_structure const &() const
{
return value_;
}
bool is_dynamic() const
{
return tag_;
}
static void *operator new(size_t n)
{
new_called_ = true;
return ::operator new(n);
}
static void operator delete(void *p)
{
::operator delete(p);
}
private:
C_structure value_;
bool tag_;
static bool new_called_;
};
bool C_wrapper::new_called_ = false;
End of Listing