August 1st, 2014, 01:36 AM
Invoking a method of a class with template
In here, T can be from the class CMesh * or CSkinnedMesh *, both have signature of GetAnimController
bool CObject<class T>::Create(LPDIRECT3DDEVICE9 pDevice, T *pMesh, float fAnimSpeed)
if(pMesh == NULL)
m_pDevice = pDevice;
m_pMesh = pMesh;
if(m_pMesh->GetAnimController() != NULL)
DWORD dwNumAnimSet = m_pMesh->GetAnimController()->GetMaxNumAnimationSets();
This maybe a flaw in my design... But I want Create to accept any kinds of meshes.
Should I create an interface or abstract class above all of those?
I have added an IMesh class that every derived classes has to have the needed interface.
But since then, I have another question, I feel that it is very cumbersome to include a template argument in every class/prototype that is associated with CObject
bool CreatePlanesFromObject(CObject *pObject, D3DXPLANE *pPlanes);
Requires me to do this
template<class T> bool CreatePlanesFromObject(CObject<T>* pObject, D3DXPLANE* pPlanes);
Any ways I can omit the template argument, because it doesn't make sense to know the Mesh type in
Last edited by lucky6969b; August 1st, 2014 at 01:58 AM.
August 1st, 2014, 08:11 AM
Re: Invoking a method of a class with template
looks like you have a somewhat awkward design. But without seeing the whole class, it's possible this is how it has to be.
CObject just being as it is, not as a template class
Create the function as a template FUNCTION rather than templatizing the whole class.
you can then specialize the function for the different types of meshes. (and provide a default one if possible).
this means you could skip potentially expensive tests like that test for GetAnimController for a mesh type that will never have one.
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!