By the implemented macro -
you can use the default constructors of an objects chain
without to know something about the chain's level :) :
CShape* CYourShapeTool::MakeCopy(CShape* pcSrcShape)
{
ASSERT(pcSrcShape);
CShape* pcResShape = STATIC_DOWNCAST(
CShape, pcSrcShape->GetRuntimeClass()->CreateObject() );
ASSERT(pcResShape);
pcResShape->Assign(pcSrcShape);
return pcResShape;
}
void TestFunction()
{
CYourShapeTool cTool;
CCircle cCircle(10, 10, 5); CCircle* pcCopyCircle = STATIC_DOWNCAST(
CCircle, cTool.MakeCopy(&cCircle) );
delete pcCopyCircle;
pcCopyCircle = NULL;
CRectangle cRect(20, 20, 50, 50); CRectangle* pcCopyRect = STATIC_DOWNCAST(
CRectangle, cTool.MakeCopy(&cRect) );
delete pcCopyRect;
pcCopyRect = NULL;
}