cassius Posted October 25, 2013 Share Posted October 25, 2013 Hi At the moment the c++ files I am using are main.cpp app.cpp app.h The listing is getting a bit long now and I want to move all my functions into their own file called functions.cpp which will have its own header file (functions.h) I am not sure where to put the include directive for this new file so that it is visible to all other files. Should I just put it in main.cpp.....or what???? Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
Thomas Posted October 25, 2013 Share Posted October 25, 2013 #ifndef _FILE_NAME_H_ #define _FILE_NAME_H_ /* code */ #endif Shouldn't you learn the language and how to use the compiler *before* trying to write games with it? Quote LINUX: Viagra for the PC. running Slackware GNU/Linux since 1996 Linux Developer Windows is a 32 bit shell for a 16 bit extension to an 8 bit Operating System designed for a 4 bit microchip by a 2 bit company which can't stand one bit of competition You can protect yourself from the 12/21/12 thing by not using the US short hand date format 21/12/12 ... Nope, that doesn't work 12/12/21 ... Doesn't work either Crisis averted... EVE-Online exclusive 21-day trial Link to comment Share on other sites More sharing options...
Josh Posted October 25, 2013 Share Posted October 25, 2013 I just use #pragma once at the top of each header file. Never had a problem with this on any compiler. To add a new CPP file in your project, you should include the header from App.h and also drag the CPP file into the project explorer panel to add it to the project. Note that this has to be done separately for Xcode, Visual Studio, and Eclipse. (Eclipse requires that you modify the makefile to add the CPP file into the build chain.) Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rick Posted October 25, 2013 Share Posted October 25, 2013 Just as a side note to structure. If you think your function count is high because you're putting them all into main or app, then that's not going to change if you put them into functions.cpp. It would seem to be you are programming more in C than C++ (that's fine) so if I were you I would start grouping functionality of functions and put them into their own source/header files so things are a little more structured. I always just use VS to create my files (I use classes though where 1 source/header is 1 class). Josh has main & app files in a different directory (because they are shared between all platforms) then where your files will be created. This means if you want to include things between his files and yours you have to find them in your include. So, make your functions.cpp/functions.h (although it's sort of a bad strategy) from VS. Then in app.h do: #include "../Projects/Windows/Functions.h" (going off memory on the paths there, but it's something like that). Quote Link to comment Share on other sites More sharing options...
Josh Posted October 25, 2013 Share Posted October 25, 2013 Sorry, you should include files from App.h, in the "Source" directory, to include all your includes from. Main.cpp varies depending on platform. Android uses a special version of it, so App.h is the one to use. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
cassius Posted October 25, 2013 Author Share Posted October 25, 2013 Yes I am programming more in c than c++ cos that's what I know best. So far its working well. I know how to add files to visual c++project . I am using windows. I just need to know where to put include directives I could try trial and error methods but its quicker and safer to ask.. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
cassius Posted October 26, 2013 Author Share Posted October 26, 2013 Thanks everybody. EDIT: got it working Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.