Re: Testing Program Question
Look at Microsoft's COM which is something which is employed with larger
code sizes. In C++ terms a COM interface is just like a Java interface
implemented as an abstract class containing just public pure virtual
functions and no implementation code and/or data. It is possible to wrap
such virtuals with a non-virtual function which can do parameter and/or
return value checking (arguably only required for debug builds) but it is
not possible to do an invariant check at the call site.
Not entirely true what I said but almost: take a look at the core COM
interface IUnknown below, note the public pure virtuals and the non-virtual
wrapper helper function (which must be inline and doesn't involve accessing
any state or any invariant check).
extern "C++"
{
MIDL_INTERFACE("00000000-0000-0000-C000-000000000046")
IUnknown
{
public:
BEGIN_INTERFACE
virtual HRESULT STDMETHODCALLTYPE QueryInterface(
/* [in] */ REFIID riid,
/* [iid_is][out] */ __RPC__deref_out void __RPC_FAR
*__RPC_FAR *ppvObject) = 0;
virtual ULONG STDMETHODCALLTYPE AddRef( void) = 0;
virtual ULONG STDMETHODCALLTYPE Release( void) = 0;
template<class Q>
HRESULT
#ifdef _M_CEE_PURE
__clrcall
#else
STDMETHODCALLTYPE
#endif
QueryInterface(Q** pp)
{
return QueryInterface(__uuidof(Q), (void **)pp);
}
END_INTERFACE
};
} // extern C++