Jump to content
  • Advertisement
Sign in to follow this  
Knight52

cannot instantiate class derived from abstract class

This topic is 2278 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was looking for a tutorial on how to import and draw animated model from .x file, and I found a tutorial. I downloaded a sample code. It appeared to be a VC++6 project. Originally, the class is devided into .h and .cpp, but I wrapped them up, and kind of copy-paste the rest of the code into my current project. It gave error "'CAllocateHierarchy' : cannot instantiate abstract class". I know I can't instantiate abstract class, but I never know I can't instantiate class derived from abstract class as well. Is this changed from VC++6 or did I do something wrong?

code:

class CAllocateHierarchy: public ID3DXAllocateHierarchy
{
public:
STDMETHOD(CreateFrame)(THIS_ LPCTSTR Name, LPD3DXFRAME *ppNewFrame)
{
LPFRAME pFrame = new FRAME;
ZeroMemory(pFrame, sizeof(FRAME));
*ppNewFrame = NULL;
if(Name)
{
int nNameSize = strlen(Name)+1;
pFrame->Name = new char[nNameSize];
memcpy(pFrame->Name, Name, nNameSize*sizeof(char));
}
else
pFrame->Name = NULL;
pFrame->pFrameFirstChild = NULL;
pFrame->pFrameSibling = NULL;
pFrame->pMeshContainer = NULL;
D3DXMatrixIdentity(&pFrame->matCombined);
D3DXMatrixIdentity(&pFrame->TransformationMatrix);
*ppNewFrame = (LPD3DXFRAME)pFrame;
pFrame = NULL;
return S_OK;
}
STDMETHOD(CreateMeshContainer)(THIS_ LPCTSTR Name,
LPD3DXMESHDATA pMeshData, LPD3DXMATERIAL pMaterials,
LPD3DXEFFECTINSTANCE pEffectInstances, DWORD NumMaterials,
DWORD *pAdjacency, LPD3DXSKININFO pSkinInfo, LPD3DXMESHCONTAINER *ppNewMeshContainer)
{
LPMESHCONTAINER pMeshContainer = new MESHCONTAINER;
ZeroMemory(pMeshContainer, sizeof(MESHCONTAINER));
*ppNewMeshContainer = NULL;

if(Name)
{
int nNameSize = strlen(Name)+1;
pMeshContainer->Name = new char[nNameSize];
memcpy(pMeshContainer->Name, Name, nNameSize*sizeof(char));
}
else
pMeshContainer->Name = NULL;

pMeshContainer->MeshData.Type = D3DXMESHTYPE_MESH;
DWORD dwFaces = pMeshData->pMesh->GetNumFaces();
pMeshContainer->NumMaterials = NumMaterials;
pMeshContainer->pMaterials9 = new D3DMATERIAL9[pMeshContainer->NumMaterials];
pMeshContainer->pAdjacency = new DWORD[dwFaces*3];
memcpy(pMeshContainer->pAdjacency, pAdjacency, sizeof(DWORD) * dwFaces*3);
LPDIRECT3DDEVICE9 pd3dDevice = NULL;
pMeshData->pMesh->GetDevice(&pd3dDevice);

pMeshData->pMesh->CloneMeshFVF(D3DXMESH_MANAGED,
pMeshData->pMesh->GetFVF(), pd3dDevice,
&pMeshContainer->MeshData.pMesh);

pMeshContainer->ppTextures = new LPDIRECT3DTEXTURE9[NumMaterials];
for(DWORD dw = 0; dw < NumMaterials; ++dw)
{
pMeshContainer->ppTextures [dw] = NULL;

if(pMaterials[dw].pTextureFilename && strlen(pMaterials[dw].pTextureFilename) > 0)
{
if(FAILED(D3DXCreateTextureFromFile(pd3dDevice,
pMaterials[dw].pTextureFilename, &pMeshContainer->ppTextures[dw])))
pMeshContainer->ppTextures [dw] = NULL;
}
}

SAFE_RELEASE(pd3dDevice);

if(pSkinInfo)
{
pMeshContainer->pSkinInfo = pSkinInfo;
pSkinInfo->AddRef();
UINT uBones = pSkinInfo->GetNumBones();
pMeshContainer->pBoneOffsets = new D3DXMATRIX[uBones];
pMeshContainer->ppFrameMatrices = new D3DXMATRIX*[uBones];
for (UINT i = 0; i < uBones; i++)
pMeshContainer->pBoneOffsets = *(pMeshContainer->pSkinInfo->GetBoneOffsetMatrix(i));
}
else

{
pMeshContainer->pSkinInfo = NULL;
pMeshContainer->pBoneOffsets = NULL;
pMeshContainer->pSkinMesh = NULL;
pMeshContainer->ppFrameMatrices = NULL;
}

pMeshContainer->pMaterials = NULL;
pMeshContainer->pEffects = NULL;
*ppNewMeshContainer = pMeshContainer;
pMeshContainer = NULL;
return S_OK;
}
STDMETHOD(DestroyFrame)(THIS_ LPD3DXFRAME pFrameToFree)
{
LPFRAME pFrame = (LPFRAME)pFrameToFree;
SAFE_DELETE_ARRAY(pFrame->Name);
SAFE_DELETE(pFrame);
return S_OK;
}
STDMETHOD(DestroyMeshContainer)(THIS_ LPD3DXMESHCONTAINER pMeshContainerBase)
{
LPMESHCONTAINER pMeshContainer = (LPMESHCONTAINER)pMeshContainerBase;
SAFE_DELETE_ARRAY(pMeshContainer->Name)
SAFE_DELETE_ARRAY(pMeshContainer->pMaterials9)
if(pMeshContainer->ppTextures)
for(UINT i = 0; i < pMeshContainer->NumMaterials; ++i)
SAFE_RELEASE(pMeshContainer->ppTextures);
SAFE_DELETE_ARRAY(pMeshContainer->ppTextures)
SAFE_DELETE_ARRAY(pMeshContainer->pAdjacency)
SAFE_DELETE_ARRAY(pMeshContainer->pBoneOffsets)
SAFE_DELETE_ARRAY(pMeshContainer->ppFrameMatrices)
SAFE_DELETE_ARRAY(pMeshContainer->pAttributeTable)
SAFE_RELEASE(pMeshContainer->pSkinMesh)
SAFE_RELEASE(pMeshContainer->MeshData.pMesh)
SAFE_RELEASE(pMeshContainer->pSkinInfo)
SAFE_DELETE(pMeshContainer)
return S_OK;
}
};


where it gives error

if(m_pFrameRoot)
{
CAllocateHierarchy Alloc;///// here
D3DXFrameDestroy(m_pFrameRoot, &Alloc);
m_pFrameRoot = NULL;
}

Share this post


Link to post
Share on other sites
Advertisement
[font="arial, helvetica, sans-serif"]Your [/font]CreateMeshContainer has the wrong signature.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!