Jump to content

  • Log In with Google      Sign In   
  • Create Account


multiple .cpp files?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 jakobnator   Members   -  Reputation: 99

Like
0Likes
Like

Posted 29 April 2011 - 09:19 PM

So I am just getting started in Game development, and I have been watching some dev marathons, and I noticed they have multiple .cpp files? I already know about header files and they are all incorparated into main.cpp but what is the point of multiple .cpp files? Can you add them all to the main.cpp file whats the difference between the .cpp and .h? Please explain in detail.

EDIT: Also came across another problem, in SDL for my game I am trying to organize my art into files so how do I load something in a file path because,
SDL_LoadBMP("BlackJack/Art/Table.png");
is not working!

Sponsor:

#2 nfries88   Members   -  Reputation: 259

Like
0Likes
Like

Posted 29 April 2011 - 09:40 PM

So I am just getting started in Game development, and I have been watching some dev marathons, and I noticed they have multiple .cpp files?

Yes. Generally, you'll have one or more related classes defined in a header file. When you implement the member functions and constructors of these classes, it is common to do so in a source (.cpp) file.

I already know about header files and they are all incorparated into main.cpp

This is not necessary in the least.

but what is the point of multiple .cpp files? Can you add them all to the main.cpp file whats the difference between the .cpp and .h? Please explain in detail.

.cpp is a "source file" and is compiled and linked automatically by an IDE.
The point in having multiple is that it's easier to manage your code if it's split up in an orderly fashion.
Looking for paid or open-source C++ programming work. Been programming since 2005. No degree.

#3 AnotherFalseProphet   Members   -  Reputation: 115

Like
0Likes
Like

Posted 29 April 2011 - 09:42 PM

I personally like to keep some parts of the program separated from the main program so provide easier readability. I don't know what the professional coders do it for, or what it's called, though.

#4 KulSeran   Members   -  Reputation: 2485

Like
1Likes
Like

Posted 29 April 2011 - 09:43 PM

So I am just getting started in Game development, and I have been watching some dev marathons, and I noticed they have multiple .cpp files? I already know about header files and they are all incorparated into main.cpp but what is the point of multiple .cpp files? Can you add them all to the main.cpp file whats the difference between the .cpp and .h? Please explain in detail.

Mandatory reading.

You split up code into multiple cpp files to organize it. A common suggestion is to place one class per cpp file, or at the very least, give one purpose to each cpp file. Once you code is inside seperate compilation units, you have to provide enough forward declarations/prototypes to make each cpp file compile. That is where the headers come in. You put the declaration of each of your public interfaces into headers, and then include those headers in any cpp file that needs to be able to call those functions. There are some exceptions, like templates, that must be contained in full in your headers so that their full definition is available at point of use.

#5 nfries88   Members   -  Reputation: 259

Like
0Likes
Like

Posted 29 April 2011 - 09:58 PM

EDIT: Also came across another problem, in SDL for my game I am trying to organize my art into files so how do I load something in a file path because,

SDL_LoadBMP("BlackJack/Art/Table.png");
is not working!


SDL_LoadBMP is for bitmap (.bmp) files. use SDL_Image and IMG_Load for a generic image loading function.
Looking for paid or open-source C++ programming work. Been programming since 2005. No degree.

#6 jakobnator   Members   -  Reputation: 99

Like
0Likes
Like

Posted 30 April 2011 - 08:42 AM


EDIT: Also came across another problem, in SDL for my game I am trying to organize my art into files so how do I load something in a file path because,

SDL_LoadBMP("BlackJack/Art/Table.bmp");
is not working!


SDL_LoadBMP is for bitmap (.bmp) files. use SDL_Image and IMG_Load for a generic image loading function.


Thats what I meant I had a predefined loading function so I just changed it to that for that, it was able to load .png files anyway, the problem is the file path what do I use if my art is in a folder inside of where the executable is because
("BlackJack/Art/Table.bmp");
is not loading that file path.




#7 nfries88   Members   -  Reputation: 259

Like
0Likes
Like

Posted 30 April 2011 - 10:39 AM



EDIT: Also came across another problem, in SDL for my game I am trying to organize my art into files so how do I load something in a file path because,

SDL_LoadBMP("BlackJack/Art/Table.bmp");
is not working!


SDL_LoadBMP is for bitmap (.bmp) files. use SDL_Image and IMG_Load for a generic image loading function.


Thats what I meant I had a predefined loading function so I just changed it to that for that, it was able to load .png files anyway, the problem is the file path what do I use if my art is in a folder inside of where the executable is because
("BlackJack/Art/Table.bmp");
is not loading that file path.




all directories sent to files will be relative to your PATH environment variable (negligible for this) and your current execution directory, which is by default the same folder as your .exe.

So if your folder is in C:/My Code/BlackJack/, and Table.bmp is in C:/My Code/BlackJack/Art/; then what you need to send to your function is merely "Art/Table.bmp".
Looking for paid or open-source C++ programming work. Been programming since 2005. No degree.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS