Inline link error

Started by
3 comments, last by sheep19 15 years, 3 months ago
I have this function:

Sint16 Sprite::y() const
{
     return offset.y;
}

If I change it to this:

inline Sint16 Sprite::y() const
{
     return offset.y;
}

error LNK2019: unresolved external symbol "public: short __thiscall Sprite::y(void)const " (?y@Sprite@@QBEFXZ) referenced in function _SDL_main I'm using Visual C++ 2008 EE
Advertisement
This should work, are you sure that the cpp file in which this definition resides is visible (is it included in the project). When you get the unresolved external error that usually means that the linker cannot find the location where the function is defined ( that can happen from a mismatch of the function signature, such as when you define a function as const in declaration and not in definition or vise-versa, so you should check that the signatures are the same ) Hope this helps.

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

declaration: (inside the class) in sprite.h

Sint16 Y() const;

and definition:

inside sprite.cpp

inline Sint16 Sprite::Y() const
{
return offset.y;
}
An inline function must be defined in every translation unit in which it is used. In practice this means that it has to go inside a header file.
Quote:Original post by SiCrane
An inline function must be defined in every translation unit in which it is used. In practice this means that it has to go inside a header file.


That explains it, thanks.

This topic is closed to new replies.

Advertisement