Why is the linker displaying such an error? (LNK2019)

Hi, can anyone help me out with this? The linker keeps giving me this error:

Sprite.obj : error LNK2019: unresolved external symbol "public: void __thiscall Sprite::SetPosition(struct tagPOINT)" (?SetPosition@Sprite@@QAEXUtagPOINT@@@Z) referenced in function "public: virtual void __thiscall Sprite::Update(void)" (?Update@Sprite@@UAEXXZ)

Sprite.obj : error LNK2019: unresolved external symbol "public: void __thiscall Sprite::SetVelocity(int,int)" (?SetVelocity@Sprite@@QAEXHH@Z) referenced in function "public: virtual void __thiscall Sprite::Update(void)" (?Update@Sprite@@UAEXXZ)

Sprite.obj : error LNK2019: unresolved external symbol "public: void __thiscall Sprite::SetVelocity(struct tagPOINT)" (?SetVelocity@Sprite@@QAEXUtagPOINT@@@Z) referenced in function "public: virtual void __thiscall Sprite::Update(void)" (?Update@Sprite@@UAEXXZ)

And I have these functions declaration inside the Sprite class:

/*****code omitted******/
virtual
void Update();
/*****more code omitted*****/

void SetPosition(int x,int y);

void SetPosition(POINT ptPosition);

void SetPosition(RECT& rcPosition)

{ CopyRect(&m_rcPosition, &rcPosition);}

void OffsetPosition(int x,int y);

POINT GetVelocity() {return m_ptVelocity;}

void SetVelocity(int x,int y);

void SetVelocity(POINT ptVelocity);

/******This is the Update function implementation, in the cpp file*****/

void Sprite::Update()

{

// Update the position

POINT ptNewPosition, ptSpriteSize, ptBoundsSize;

ptNewPosition.x = m_rcPosition.left + m_ptVelocity.x;

ptNewPosition.y = m_rcPosition.top + m_ptVelocity.y;

ptSpriteSize.x = m_rcPosition.right - m_rcPosition.left;

ptSpriteSize.y = m_rcPosition.bottom - m_rcPosition.top;

ptBoundsSize.x = m_rcBounds.right - m_rcBounds.left;

ptBoundsSize.y = m_rcBounds.bottom - m_rcBounds.top;

// Check the bounds

// Wrap?

if (m_baBoundsAction == BA_WRAP)

{

if ((ptNewPosition.x + ptSpriteSize.x) < m_rcBounds.left)

ptNewPosition.x = m_rcBounds.right;

elseif (ptNewPosition.x > m_rcBounds.right)

ptNewPosition.x = m_rcBounds.left - ptSpriteSize.x;

if ((ptNewPosition.y + ptSpriteSize.y) < m_rcBounds.top)

ptNewPosition.y = m_rcBounds.bottom;

elseif (ptNewPosition.y > m_rcBounds.bottom)

ptNewPosition.y = m_rcBounds.top - ptSpriteSize.y;

}

// Bounce?

elseif (m_baBoundsAction == BA_BOUNCE)

{

BOOL bBounce = FALSE;

POINT ptNewVelocity = m_ptVelocity;

if (ptNewPosition.x < m_rcBounds.left)

{

bBounce = TRUE;

ptNewPosition.x = m_rcBounds.left;

ptNewVelocity.x = -ptNewVelocity.x;

}

elseif ((ptNewPosition.x + ptSpriteSize.x) > m_rcBounds.right)

{

bBounce = TRUE;

ptNewPosition.x = m_rcBounds.right - ptSpriteSize.x;

ptNewVelocity.x = -ptNewVelocity.x;

}

if (ptNewPosition.y < m_rcBounds.top)

{

bBounce = TRUE;

ptNewPosition.y = m_rcBounds.top;

ptNewVelocity.y = -ptNewVelocity.y;

}

elseif ((ptNewPosition.y + ptSpriteSize.y) > m_rcBounds.bottom)

{

bBounce = TRUE;

ptNewPosition.y = m_rcBounds.bottom - ptSpriteSize.y;

ptNewVelocity.y = -ptNewVelocity.y;

}

if (bBounce)

SetVelocity(ptNewVelocity);

}

// Stop (default)

else

{

if (ptNewPosition.x < m_rcBounds.left ||

ptNewPosition.x > (m_rcBounds.right - ptSpriteSize.x))

{

ptNewPosition.x = max(m_rcBounds.left, min(ptNewPosition.x,

m_rcBounds.right - ptSpriteSize.x));

SetVelocity(0, 0);

}

if (ptNewPosition.y < m_rcBounds.top ||

ptNewPosition.y > (m_rcBounds.bottom - ptSpriteSize.y))

{

ptNewPosition.y = max(m_rcBounds.top, min(ptNewPosition.y,

m_rcBounds.bottom - ptSpriteSize.y));

SetVelocity(0, 0);

}

}

SetPosition(ptNewPosition);

}

/*****End Update function implementation********************/

What could be wrong?

[6714 byte] By [WizMan] at [2007-12-16]
# 1
Hello,

The linker is telling you that it cannot find the SetPosition and SetVelocity functions. You declared them in the header file, which will satisfy the compiler. But the linker needs to know the function code.

In the implementation, write out the SetPosition and SetVelocity functions, like:

void Sprite::SetPosition( int x, int y )
{

m_x = x;
m_y = y;
}

Or however you are going to implement it.

FlamTaps2 at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...
# 2
Thanks a lot, that solved the problem. I guess I forgot to implement the functions because I hadn't used them yet and thought I could get away with it Big Smile
WizMan at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...