Sign in to follow this  

inline method cuasing linking error

This topic is 4304 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
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

This topic is 4304 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this