Sign in to follow this  

Why can't I inline?

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

I'm trying to make some functions inline, but keep getting link errors I have this simple method: void Cboid::accelerate(float a) { vel += a; } Which works fine, but whenever I inline it I get: error LNK2019: unresolved external symbol "public: void __thiscall Cboid::accelerate(float)" (?accelerate@Cboid@@QAEXM@Z) referenced in function "void __cdecl doLogic(void)" (?doLogic@@YAXXZ) What does this mean? MSDN isn't very helpful. I'm using VS2003 .net if that helps.

Share this post


Link to post
Share on other sites
A function explicitly declared as "inline" must have its body defined in every translation unit it is used in. In other words, you need to define the body in the header file (or, as is often done, in an .inl file that the header file includes after the class definition). Or just put the body in the class itself.

Share this post


Link to post
Share on other sites
HAZAAA!

It works! yes I put the code in the header file and now it goes. Didn't know that, was always told to keep code out of .h files, although that was when I was learning C.

Thanks Sneftel

Share this post


Link to post
Share on other sites
I am by no means an expert programming, so correct me if I am wrong...

All functions, etc... should go into the .cpp file
All class declarations and function declarations should go in the header file.

One of the exceptions is for inline functions, which must be included in the header file (so it is included in the translation unit).

Is your inline function in the header file? Try moving it there and see what happens... I hope this helps.

Share this post


Link to post
Share on other sites

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