Sign in to follow this  
BreathOfLife

include directories / inlining

Recommended Posts

Well, with a solid hour and a half a tweaking, I think I have at least discovered the root of my namespace problem. Its not a namespace problem. I simply dont know wnough about my tools. Ive read a bunch of pages on the MSDN but cant seem to find anything, at least nothing in terms that is making things click. What I am looking to do is have chunks of code, generally in the .h/.cpp pairs, in a folder in the directory I keep the source code Im working on. I was hoping then I wouldnt need to add each .cpp to the project, and could just #include <header.h>, and I get an unresolved external. So now Im sure that if I want to be lazy and just have to #include something, I cant have a .cpp. But its me, so because Im sure doesnt mean its true. The way around this I can see is just putting the function bodies in the header. For most of the headers Im talking about they're just small and fairly simple, so I dont see a problem with inlining them. So two questions really 1) am I in fact stuck manually adding .cpps instead of getting to be lazy? and 2) is there any downside/drawback to the inline definitions of small functions like that? if anything all that happens is the compiler links them like regular function calls if it wants to correct?

Share this post


Link to post
Share on other sites
1) basically yes. the header files declare functions and classes and such so you can refer to them in your code when it is included. the cpp files actually define those function and such, and must be compiled into your project in order to be used. well technically you could also compile them into a static or dynamic library but then you would still have to link those in at some point.

2) not that i know of, other than it can get messy as they get bigger, and might take longer to compile in some case (if you change a small part that could have been in its own header and cpp file, but instead you lumped it in your uber header).

Share this post


Link to post
Share on other sites
You have to specify which files are in your project so that the compiler knows what to compile. Header files can be #include'ed without explicitly adding them to a project, usually because they are inlined by the compiler as it compiles a known cpp file.

However. This is bad practice. Whenever possible, always explicitly add any source files to your IDE's project file or at least make sure the IDE's environment is setup to inform the compiler where these files are. (this extends to 3rd party libraries, but becomes a much more complicated issue..)

Definitely, definitely, read this famous article on GameDev.net.

Share this post


Link to post
Share on other sites

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