Putting it all together: When I first began to learn C++ about a year ago, I was used to the good old-fashioned one-source-file model. It took me weeks to figure out how C++ arranged and compiled its source and header files. It took me over a month to figure out how to use this arrangement to create globals instantly. I am writing this to save the other beginners out there the heartache. Here is my basic model that I use in all my applications:
As you can see from this setup, you can add a fully application-wide global simply by declaring it in the winmain.cpp and then putting it in the globals.h file with "extern" in front of it! Also, every file in the entire project can access every global, function, class, enumeration, or whatever you want! To add a new source file (say, another class), all you have to do is create the files, add #include "newclass.h" with the other #includes in globals.h, put #include "globals.h" in newclass.cpp, and your new files are instantly plugged into the rest of the application's functionality and data. I hope this helped you guys. Questions, comments, whatever, e-mail me at benbeandogdilts@cs.com. Visit my web page at www.geocities.com/benbeandogdilts. Have fun, guys! Discuss this article in the forums
See Also: © 1999-2011 Gamedev.net. All rights reserved. Terms of Use Privacy Policy
|