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

## 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 on other sites
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 on other sites
Did you originally have the function definition in the header file for the class, or in the source file (.cpp)?

##### 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!

1. 1
2. 2
3. 3
4. 4
frob
20
5. 5
JoeJ
20

• 11
• 11
• 12
• 13
• 9
• ### Forum Statistics

• Total Topics
632214
• Total Posts
3004858

×