I’m building a mfc application that will enable the user to draw graphical objects (something like ms paint). But for some reason I’m getting the following linker error:
CElement.obj : error LNK2001: unresolved external symbol “public: virtual void __thiscall CElement::Draw(class CDC *)” (?Draw@CElement@@UAEXPAVCDC@@@Z).
I know it’s something related to the virtual draw function in the CPolygon class. But what hat exactly is causing it?
//CElement.h
class CElement : public CObject
{
public:
virtual ~CElement();
virtual void Draw(CDC* pDC);
};
NOTE: CElement will act as a base class for all other classes like CPolyline and CRectangle. The Draw function is virtual- an example of polymorphism, CElement’s Draw(CDC* pDC) will be overridden by the Draw() functions of the derived classes
class CPolygon : public CElement
{
public:
CPolygon(CPoint mFirstPoint,CPoint mSecondPoint);
~CPolygon(void);
virtual void Draw(CDC* pDC);
---------------------------------------------------------------------------------------
//CElement.cpp
#include "CElement.h"
//constructors for the class
void CPolygon::Draw(CDC* pDC)
{
pDC->MoveTo(mStartPoint);
pDC->LineTo(mEndPoint);
Well as the error message says you have not defined a body for the function
either define it or make the class abstract i.e. derived classes must implement it.
or