Re: Interface implementation
Galian wrote:
[..]
This is my code. Task is next: I want write template class, CUnknown,
with implemented nessesary methods (Queryinterface, Release ...), to
use it for other classes.
CUnknown:
template < class ClassType, REFIID ObjectIID >
class CUnknown : public IUnknown
What's "IUnknown"? Are we supposed to know about it? (pun intended)
I am guessing that it's the base interface you have and it's abstract.
{
protected:
// IUnknown methods.
virtual STDMETHODIMP QueryInterface( REFIID riid, void** ppv )
{
if ( ppv == NULL )
{
return E_POINTER;
}
if ( riid == *ObjectIID || riid == IID_IUnknown )
{
*ppv = static_cast< ClassType* >( this );
AddRef();
return S_OK;
}
*ppv = NULL;
return E_NOINTERFACE;
}
virtual STDMETHODIMP_( ULONG ) AddRef()
{
return InterlockedIncrement( &m_cRef );
}
virtual STDMETHODIMP_( ULONG ) Release()
{
LSCOPE( "CMediaBuffer::Release" );
LONG lRef = InterlockedDecrement( &m_cRef );
if ( lRef == 0 )
{
delete this;
// m_cRef is no longer valid! Return lRef.
}
return lRef;
}
LONG m_cRef;
};
#include "Unknown.h"
I am guessing that's where your 'class CUnknown' is defined, or is it?
class ISMSNotificationHandler
{
public:
virtual void HandleSMSMessageReceived( const CEOID messageID ) = 0;
};
// IMAPIAdviseSink also derived from IUnknown
class CAdviseSinc
// This is my CUnknown,but anyway "Cannot instantiate abstract
class" error
Does it say what function prevents it from being instantiated?
public virtual CUnknown< CAdviseSinc, IID_IMAPIAdviseSink >
, public virtual IMAPIAdviseSink
{
public:
CAdviseSinc();
~CAdviseSinc();
private:
ULONG OnNotify( ULONG cNotif, LPNOTIFICATION lpNotifications );
};
OK. Try to change the beginning of the definition of 'CUnknown' to
template < class ClassType, REFIID ObjectIID >
class CUnknown : virtual public IUnknown
^^^^^^^
Also, do the same with IMAPIAdviseSink. What you're doing is telling
the compiler that some pure virtual functions in your 'CAdviseSink'
only exist in a single base class instance and that they are happily
overridden by the corresponding functions in 'CUnknown<blah,blah>'.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask