Original Post
OK, so I'm making fake objects for COM interfaces (ID3D11BlendState, etc.) and I'd like to coalesce the implementations of the base classes:
IUnknown
ID3D11DeviceChild
ID3D11BlendState
ID3D11RasterizerState
so that I don't have to keep repeating the definitions of the members of ID3D11DeviceChild in the implementations of ID3D11BlendState. I thought this was what the virtual keyword was for when declaring class hierarchies, but apparently I'm doing something wrong. If I do this:
class FakeD3D11DeviceChild : public ID3D11DeviceChild
{
public:
FakeD3D11DeviceChild()
{
}
// IUnknown
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) { throw NotImplementedException(); }
virtual ULONG STDMETHODCALLTYPE AddRef() { throw NotImplementedException(); }
virtual ULONG STDMETHODCALLTYPE Release() { throw NotImplementedException(); }
// ID3D11DeviceChild
virtual void STDMETHODCALLTYPE GetDevice(ID3D11Device **ppDevice) { throw NotImplementedException(); }
virtual HRESULT STDMETHODCALLTYPE GetPrivateData(REFGUID guid, UINT *pDataSize, void *pData) { throw NotImplementedException(); }
virtual HRESULT STDMETHODCALLTYPE SetPrivateData(REFGUID guid, UINT DataSize, const void *pData) { throw NotImplementedException(); }
virtual HRESULT STDMETHODCALLTYPE SetPrivateDataInterface(REFGUID guid, const IUnknown *pData) { throw NotImplementedException(); }
};
class FakeD3D11BlendState : public ID3D11BlendState, virtual public FakeD3D11DeviceChild
{
public:
FakeD3D11BlendState() : FakeD3D11DeviceChild()
{
}
// ID3D11BlendState
virtual void STDMETHODCALLTYPE GetDesc(D3D11_BLEND_DESC *pDesc) { throw NotImplementedException(); }
};
Then when I try to instantiate FakeD3D11BlendState, I get errors like this:
1>d:\projects\d3d11helpers\testd3d11helpers\testblenddescription.cpp(36) : error C2259: 'FakeD3D11BlendState' : cannot instantiate abstract class
1> due to following members:
1> 'HRESULT IUnknown::QueryInterface(const IID &,void **)' : is abstract
1> c:\program files\microsoft sdks\windows\v6.0a\include\unknwn.h(116) : see declaration of 'IUnknown::QueryInterface'
1> 'ULONG IUnknown::AddRef(void)' : is abstract
1> c:\program files\microsoft sdks\windows\v6.0a\include\unknwn.h(120) : see declaration of 'IUnknown::AddRef'
1> 'ULONG IUnknown::Release(void)' : is abstract
1> c:\program files\microsoft sdks\windows\v6.0a\include\unknwn.h(122) : see declaration of 'IUnknown::Release'
1> 'void ID3D11DeviceChild::GetDevice(ID3D11Device **)' : is abstract
1> c:\dxsdk\include\d3d11.h(1316) : see declaration of 'ID3D11DeviceChild::GetDevice'
1> 'HRESULT ID3D11DeviceChild::GetPrivateData(const GUID &,UINT *,void *)' : is abstract
1> c:\dxsdk\include\d3d11.h(1320) : see declaration of 'ID3D11DeviceChild::GetPrivateData'
1> 'HRESULT ID3D11DeviceChild::SetPrivateData(const GUID &,UINT,const void *)' : is abstract
1> c:\dxsdk\include\d3d11.h(1328) : see declaration of 'ID3D11DeviceChild::SetPrivateData'
1> 'HRESULT ID3D11DeviceChild::SetPrivateDataInterface(const GUID &,const IUnknown *)' : is abstract
1> c:\dxsdk\include\d3d11.h(1336) : see declaration of 'ID3D11DeviceChild::SetPrivateDataInterface'
Obviously I'm not doing this right. I need multiple inheritance so I can declare that FakeD3D11BlendState derives from my base implementation and ID3D11BlendState. However, I don't want to have to repeat the implementation of the members in the base class. What am I missing here? I thought that applying virtual to the base implementation class was going to take care of it, but obviously not.