Jump to content
  • Advertisement
Sign in to follow this  
Nauht

inline functions not linking?

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

Hi, I'm using Visual Studio 2003 at the moment and I have a few of these inline functions within a C++ class:
inline C3DModel* GameObject::getModel()
{
	return &mModel;
}
I have set the flag /Ob1 so that the compiler would expand inline functions however when it comes to linking, the compiler complains that it can't find the inline functions:
app.obj : error LNK2019: unresolved external symbol "public: class C3DModel * __thiscall GameObject::getModel(void)" (?getModel@GameObject@@QAEPAVC3DModel@@XZ) referenced in function "void __cdecl DrawModel(class GameObject *)" (?DrawModel@@YAXPAVGameObject@@@Z)
Release/assign2.exe : fatal error LNK1120: 1 unresolved externals
The way I get around this is by defining the inline function within the class declaration but does anybody know what I did wrong when I try to use the inline keyword? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
An inline function is automatically given internal linkage, which means that if it is defined inside a cpp file, it can't be seen in any other file. If you want other files to use it, you must put it in a header file so that it can be defined where ever it is needed.

Share this post


Link to post
Share on other sites
Did you originally have the function definition in the header file for the class, or in the source file (.cpp)?

Share this post


Link to post
Share on other sites
I have the declaration within the class in the header file:


class GameObject
{
public:
C3DModel* getModel();

...
}


But where I define the function and use the inline keyword is in the .cpp file. So you're right John - reading this (http://msdn2.microsoft.com/en-us/library/bw1hbe6y(VS.71).aspx) MSDN article more closely, it says:
"A class member function defaults to external linkage unless a definition for that function contains the inline specifier. "

Thanks for the pointer!

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!