开发者

c++ having trouble with abstract class

I have this class that will help me with animated meshes.

class CAllocateHierarchy: public ID3DXAllocateHierarchy
{
public:
    STDMETHOD(CreateFrame)(THIS_ LPCTSTR Name, LPD3DXFRAME *ppNewFrame);
    STDMETHOD(CreateMeshContainer)(THIS_ LPCTSTR Name, LPD3DXMESHDATA pMeshData,
                            LPD3DXMATERIAL pMaterials, LPD3DXEFFECTINSTANCE pEffectInstances, DWORD NumMaterials, 
                            DWORD *pAdjacency, LPD3DXSKININFO pSkinInfo, 
                            LPD3DXMESHCONTAINER *ppNewMeshContainer);
    STDMETHOD(DestroyFrame)(THIS_ LPD3DXFRAME pFrameToFree);
    STDMETHOD(DestroyMeshContainer)(THIS_ LPD3DXMESHCONTAINER pMeshContainerBase);
    CAllocateHierarchy(CMyD3DApplication *pApp) :m_pApp(pApp) {}开发者_StackOverflow
public:
    CMyD3DApplication* m_pApp;
};

but when i try to intallizes a class like CAllocateHierarchy allloc(this); i will get error. 16 IntelliSense: object of abstract class type "CAllocateHierarchy" is not allowed: c:\users\owner\documents\visual studio 2010\projects\monopoly\monopoly\monopoly.cpp 186


The error message indicates that you didn't override all the abstract methods from the interface ID3DXAllocateHierarchy.

Looking through the arguments, I see that you forgot the "const" for several arguments to the CreateMeshContainer() method. As a result, the C++ compiler thinks this is a different method, and complains that the original CreateMeshContainer() is still abstract.

From http://msdn.microsoft.com/en-us/library/bb205621(v=VS.85).aspx

HRESULT CreateMeshContainer(
  [in]           LPCSTR Name,
  [in]           const D3DXMESHDATA *pMeshData,
  [in]           const D3DXMATERIAL *pMaterials,
  [in]           const D3DXEFFECTINSTANCE *pEffectInstances,
  [in]           DWORD NumMaterials,
  [in]           const DWORD *pAdjacency,
  [in]           LPD3DXSKININFO pSkinInfo,
  [out, retval]  LPD3DXMESHCONTAINER *ppNewMeshContainer
);

So the solution is: Add 'const' to several arguments (but see update below).

Update: You also are missing some '*' in your arguments. Apparently you have declared the CreateMeshContainer to take arguments by value, while it should be by const pointer. Copy-pasting the declaration from the msdn link and removing the [in] tags might be the fastest way to get a correct declaration.

Suggestion: Using a different compiler might help to generate more insightful error messages, as might setting the warning level as high as possible. Some compilers list the methods that are still abstract. Some compilers might warn that your CreateMeshContainer() is not overriding the virtual CreateMeshContainer() in the interface. Every suggestion what is wrong could be helpful.


Your subclass doesn't implement at least one of the pure virtual methods (marked virtual whatever = 0) of its base class. You must implement all such methods in order to instantiate your subclass.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜