Jump to content
  • Advertisement
Sign in to follow this  
maya18222

header files

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

Am i right in thinking that you can only define functions in headers if they are inline? Lets say that i have a header file which i want to contain lots of little functions, and i want to include this header in lots of places in my code, are my only 2 options. 1. make all functions inline 2. .h for declarations, .cpp for definitions

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by maya18222
Am i right in thinking that you can only define functions in headers if they are inline?
No. It's when you want to inline a function that the definition has to be in the header to make it accessible. And remember, even with the inline keyword, the compiler will choose to inline or not. You should have a look here.

Share this post


Link to post
Share on other sites
yes you are correct. If a function is not keyword inline and it's in a header and that header is #include'd in multiple .cpp files you will get linker errors of "previously defined".

-me

Share this post


Link to post
Share on other sites
Quote:
Original post by Palidine
yes you are correct. If a function is not keyword inline and it's in a header and that header is #include'd in multiple .cpp files you will get linker errors of "previously defined".
If you declare function as static, it does not have to be inline.

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!