# inline method cuasing linking error

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

## 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 on other sites
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. :)

• 10
• 17
• 9
• 14
• 41