Derived class from abstract class(COleControl in MFC) gave error while allocation memory
-
Created a class i.e. CFlipCustomViewer derived from COleConrol class(abstact class)and overridden the "virtual void OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)" method of COleControl class in the void CFlipCustomViewer::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid).I tried to call this in OnInitDialog() method of my dialog class of the application.Here the code snippets.. BOOL CFlip::OnInitDialog() { //having a CStatic as a place holder and then //create the flip custom control in InitDialog COleControl* ptrOleControl; //abstract base class pointer CFlipCustomViewer* ptrFlipCustomViewer; //derived class pointer ptrOleControl = ptrFlipCustomViewer; //derived class pointer assigned to abstract base class pointer ptrOleControl = new CFlipCustomViewer(); //error in this instantiation of derived one CDC* pdc = GetDC(); //get the device context CRect rcBounds; CRect rcInvalid; GetClientRect( &rcBounds); GetClientRect( &rcInvalid); ptrOleControl->OnDraw(pdc,rcBounds,rcInvalid);//place holder for flipping action CDialog::OnInitDialog(); return TRUE; } **************************************************************************************** but while compiling i am getting the following errors as below : error C2259: 'CFlipCustomViewer' : cannot instantiate abstract class due to following members: d:\fancyviewer\flipsample\flipcustomviewer.h(14) : see declaration of 'CFlipCustomViewer' d:\fancyviewer\flipsample\flip.cpp(200) : warning C4259: 'long __thiscall COleControl::GetClassID(struct _GUID *)' : pure virtual function was not defined d:\program files\microsoft visual studio\vc98\mfc\include\afxctl.h(683) : see declaration of 'GetClassID' d:\fancyviewer\flipsample\flip.cpp(200) : warning C4259: 'unsigned int __thiscall COleControl::GetUserTypeNameID(void)' : pure virtual function was not defined d:\program files\microsoft visual studio\vc98\mfc\include\afxctl.h(936) : see declaration of 'GetUserTypeNameID' d:\fancyviewer\flipsample\flip.cpp(200) : warning C4259: 'unsigned long __thiscall COleControl::GetMiscStatus(void)' : pure virtual function was not defined d:\program files\microsoft visual studio\vc98\mfc\include\afxctl.h(937) : see declaration of 'GetMiscStatus' d:\fancyviewer\flipsample\flip.cpp(200) : error C2259: 'CFlipCustomViewer' : cannot instantiate abstract class due to following members: d:\fancyviewer\flipsample\flipcustomviewer.h(14) :
-
Created a class i.e. CFlipCustomViewer derived from COleConrol class(abstact class)and overridden the "virtual void OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)" method of COleControl class in the void CFlipCustomViewer::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid).I tried to call this in OnInitDialog() method of my dialog class of the application.Here the code snippets.. BOOL CFlip::OnInitDialog() { //having a CStatic as a place holder and then //create the flip custom control in InitDialog COleControl* ptrOleControl; //abstract base class pointer CFlipCustomViewer* ptrFlipCustomViewer; //derived class pointer ptrOleControl = ptrFlipCustomViewer; //derived class pointer assigned to abstract base class pointer ptrOleControl = new CFlipCustomViewer(); //error in this instantiation of derived one CDC* pdc = GetDC(); //get the device context CRect rcBounds; CRect rcInvalid; GetClientRect( &rcBounds); GetClientRect( &rcInvalid); ptrOleControl->OnDraw(pdc,rcBounds,rcInvalid);//place holder for flipping action CDialog::OnInitDialog(); return TRUE; } **************************************************************************************** but while compiling i am getting the following errors as below : error C2259: 'CFlipCustomViewer' : cannot instantiate abstract class due to following members: d:\fancyviewer\flipsample\flipcustomviewer.h(14) : see declaration of 'CFlipCustomViewer' d:\fancyviewer\flipsample\flip.cpp(200) : warning C4259: 'long __thiscall COleControl::GetClassID(struct _GUID *)' : pure virtual function was not defined d:\program files\microsoft visual studio\vc98\mfc\include\afxctl.h(683) : see declaration of 'GetClassID' d:\fancyviewer\flipsample\flip.cpp(200) : warning C4259: 'unsigned int __thiscall COleControl::GetUserTypeNameID(void)' : pure virtual function was not defined d:\program files\microsoft visual studio\vc98\mfc\include\afxctl.h(936) : see declaration of 'GetUserTypeNameID' d:\fancyviewer\flipsample\flip.cpp(200) : warning C4259: 'unsigned long __thiscall COleControl::GetMiscStatus(void)' : pure virtual function was not defined d:\program files\microsoft visual studio\vc98\mfc\include\afxctl.h(937) : see declaration of 'GetMiscStatus' d:\fancyviewer\flipsample\flip.cpp(200) : error C2259: 'CFlipCustomViewer' : cannot instantiate abstract class due to following members: d:\fancyviewer\flipsample\flipcustomviewer.h(14) :
You need to override all the pure virtual functions of an abstract base class, but why not just derive from from CWnd instead?
- S 50 cups of coffee and you know it's on!