Sign in to follow this  

cannot instantiate class derived from abstract class

This topic is 2061 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:
[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[i] = *(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[i]);
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;
}
};
[/CODE]

where it gives error
[CODE]
if(m_pFrameRoot)
{
CAllocateHierarchy Alloc;///// here
D3DXFrameDestroy(m_pFrameRoot, &Alloc);
m_pFrameRoot = NULL;
}
[/CODE]

Share this post


Link to post
Share on other sites

This topic is 2061 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this