Sign in to follow this  

header files

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

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