Jump to content

multiple cpp files.


cassius
 Share

Recommended Posts

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????

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

#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?

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 :lol:

 

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

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.)

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

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).

Link to comment
Share on other sites

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.

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

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..

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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...