   .cpp and .h
  Alright, so I'm writing this nice program in GL, but my question deals with more of how to organize the code.Basically, I want main.cpp to be uncluttered with only the update() and render() functions.  I can do this already, but in a kind of weird way.Right now, I have main.cpp organized as said, but it includes .h files with all the GL code.If I seperate the functions into various .cpp files, the compiler gives me crap about functions not being initialized.  Fair enough, seeing as how the compiler builds each .cpp file first and links them together in the end.  So I made a .h file with all the function definitions and then defined them with code in the .cpp files.  I included this .h file in all of the .cpp files.I thought this would be nice.  Keep the code in the .cpp files and the definitions in the .h file.  But when I went to compile it I got error saying how each of the functions was already defined and that defining it again is illegal.  I was under the impression that only doing this:bool abcdef(int a, int b, int c);at first and then later:bool abcdef(int a, int b, int c) {   // some code}was nice and dandy.Is there something I'm missing.. or maybe a better way to organize code?Thanks a bunch.   
  Does  this article answer your questions?   ;  Sounds like you need include guards.i.e., in your each of your .h files, at the start put something like:#ifndef _FILE_NAME_H_#define _FILE_NAME_H_and at the end put#endif // _FILE_NAME_H_Obviously replace _FILE_NAME_H_ with the name of the file.This will (probably) prevent "already defined" errors.  It is good practice to have .h/.cpp file pairs, with the .h file containing declarations only for the definitions in the .cpp file.   ;Quote:Original post by ratbag_mcSounds like you need include guards.i.e., in your each of your .h files, at the start put something like:#ifndef _FILE_NAME_H_#define _FILE_NAME_H_and at the end put#endif // _FILE_NAME_H_Obviously replace _FILE_NAME_H_ with the name of the file.This will (probably) prevent "already defined" errors.  It is good practice to have .h/.cpp file pairs, with the .h file containing declarations only for the definitions in the .cpp file.Using underscores followed by capital letters( or double underscores followed by anything ) is a bad idea, as the c++ standard reserves such names for the compiler.   ;  Do #ifndef guards help?Put this in your .h file:#ifndef HEADER_H#define HEADER_H...declarations go here...#endifAnd you should replace HEADER_H with a unique symbol for each header(typically, the file's name with '_H' at the end).Edit: ouch, I'm terribly slow. Must improve my typing skillz.   ;  Here is a example of how to do it://Functions.cpp#include "Functions.h"std::string MyString = "Hello World!";void MyFunc(){    std::cout << MyString;}//Functions.h#ifndef _FUNCTIONS_H#define _FUNCTIONS_Hextern std::string MyString = "Hello World!";extern void MyFunc();#endif//main.cpp#include "Functions.h"int main(){   MyFunc();   return 0;};Quote:Original post by Servant of the LordHere is a example of how to do it:A really bad example because... Quote:Original post by rip-offUsing underscores followed by capital letters( or double underscores followed by anything ) is a bad idea, as the c++ standard reserves such names for the compiler.;  Servant OTL > And you mean #include "functions.h" I guess :)   ;Quote:Original post by phantomQuote:Original post by Servant of the LordHere is a example of how to do it:A really bad example because... Quote:Original post by rip-offUsing underscores followed by capital letters( or double underscores followed by anything ) is a bad idea, as the c++ standard reserves such names for the compiler.I've never had problems with that, and I thought the standard was double underscores? __TIME__ not _TIME_, even so, simple use lowercase then. THe OP can use whatever namingscheme he wishes, I was just showing him essentially how its done.Still though, has anyone actaully had a problem using all caps and underscores? Should this be something I should really avoid?   ;Quote:Original post by jantaAnd you mean #include "functions.h" I guess :)Dang, now I feal stupid. [lol]That was a mistake on my part, definately. Fixed it.   