• ### Popular Now

• 9
• 11
• 9
• 20
• 12

#### Archived

This topic is now archived and is closed to further replies.

# inline functions problem

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

## Recommended Posts

Hi everyone, When I try to make some functions inline using VC++ 6.0 - I get this error: Flock.obj : error LNK2001: unresolved external symbol "public: void __thiscall Boid::setCrashed(bool)" (?setCrashed@Boid@@QAEX_N@Z) Debug/prototype4.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. The compiler doesnt mind when I make some functions inline but some it just wont allow. Why is this? I hope someone can help. Thanks, Tim.

##### Share on other sites
There are issues regarding external references and inline. Read the manual, read the C++ standard, search MSDN. Keep trying.

##### Share on other sites
Yes thats correct. Check the MSDN docs, but the general idea goes something like this:

If the function is inline, it really should be short. But anyway, an inline function for a class must be written in the same header as the class, INSIDE the class declaration:

class MyClass
{
public:
inline void DoSomething(void) { return; }
};

will work,
class MyClass
{
public:
inline void DoSomething(void);
};
inline void MyClass::DoSomething(void)
{
return;
}
will not work.

-----------------------------
The sad thing about artificial intelligence is that it lacks artifice and therefore intelligence.

##### Share on other sites
quote:
Original post by Promit
...INSIDE the class declaration

That''s the only part that isn''t true. It has to be in the same file as the declaration, and should be short. The compiler, however, is free to ignore your request to inline a function.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!

##### Share on other sites
quote:
Original post by Oluseyi
The compiler, however, is free to ignore your request to inline a function.

Even with __forceinline?

##### Share on other sites
Ok, but the question was VC specific, so I thought I''d ask.

##### Share on other sites
You have to link a specific library!

Go to the project configuration -> linker
and add the needed library

If the right library linked, it should compile well.

Or the linker cannot link your function, then i have no idea

##### Share on other sites
This simply just isnt true. VC++ will complain about inlining and you can force it to. In your implementation file (.cpp) make sure you use the extern keyword ex:

  extern inline void Boid::setCrashed(bool b){........}

now this will force VC++ to try to inline but its not garunteed it will, also this will cause the compiler to spit up a few warnings telling that the extern keyword is invalid for class definitions but dont worry, ive been using this in my project and it hasnt caused 1 error.

##### Share on other sites
quote:
Original post by Promit
Yes thats correct. Check the MSDN docs, but the general idea goes something like this:

If the function is inline, it really should be short. But anyway, an inline function for a class must be written in the same header as the class, INSIDE the class declaration:

Is this behaviour intended, i.e. actually part of the c++ standard? Or will it be sorted out in VC 7?

- seb