Jump to content
  • Advertisement
Sign in to follow this  
3dmodelerguy

inline method cuasing linking error

This topic is 4639 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

it seems that when i declare any function inside a class, or method, inline i get a linking error everything time i try to use it but if it not not inline than it works fine. currently it is fine that i don't use the inline but would still ike to know why this is happening any one know why this would be happening. here are the linking error i get. main.obj : error LNK2019: unresolved external symbol "public: int __thiscall NFile::CImageFile::GetImageHeight(void)const " (?GetImageHeight@CImageFile@NFile@@QBEHXZ) referenced in function "void __cdecl InitOpenGL(int,int)" (?InitOpenGL@@YAXHH@Z)

Share this post


Link to post
Share on other sites
Advertisement
My guess would be is that your call to CImageFile::GetImageHeight is being called from InitOpenGL, but is marked as inline and the compiler was unable to find the source for the function.

If you define an inline function in a class in a header that gets #included by other source files, you will need to place the code for that function inside the header as well. Something like:
class CImageFile
{
private:
int width, height;
// ... stuff ...

public:
// ... more stuff ...
inline int GetImageHeight(void);
};


inline int CImageFile::GetImageHeight(void)
{
return height;
}



All in the same header file. In the source for CImageFile, you no longer need the function declaration.

You can also do:
class CImageFile
{
private:
int width, height;
// ... stuff ...

public:
// ... more stuff ...
int GetImageHeight(void) { return height; }
};



More or less a matter of preferred style. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!