Very New - Learning the Basics

Started by
4 comments, last by blakedev 16 years, 8 months ago
Hi, I'm still very new to C++ and still getting the basics. I've got the real easy stuff down such as variables, functions, and arrays. However, I have some specific questions. I know that you need to use #include directives such as #include <iostream> to do basic things. I don't fully understand what happens when you #include "game.h" for example, in which case game.h is a header file in your project. In plain English what is achieved from #include "(header file).h"? Also, what is the difference between Header .h, Source .cpp, and Resource Files? (I am using Visual C++ 2005 Express Edition.) Are these files all using C++ coding? Are they used for different purposes? As a side note: I have a basic book that teaches DirectX game programming with C++ (called Beginning Game Programming: Second Edition by Jonathan S. Harbor), and The Complete Reference to C++ Fourth Edition by Herbert Schildt. My goal right now is to get good enough with C++ and DirectX to make some fun 2D games with sprites that I render from Blender (which I'm also learning). Before I can do this game programming I have to be realistic though and learn about things such as the questions I asked above. Thanks a lot to anyone that discusses these points with me! I really appreciate it - you C++ Programmers have probably forgotten how difficult it was to start learning from scratch! Thanks again, Brent
Advertisement
If you need additional resources, there are some free books in my signature.

Quote:
I don't fully understand what happens when you #include "game.h" for example, in which case game.h is a header file in your project. In plain English what is achieved from #include "(header file).h"?


When the compiler (really the pre-processor) sees #include "Game.h", it copies the contents of Game.h into the file that included it.

Quote:
Also, what is the difference between Header .h, Source .cpp, and Resource Files? (I am using Visual C++ 2005 Express Edition.) Are these files all using C++ coding? Are they used for different purposes?


Resource files are Windows-specific and don't have anything to do with C++. Header files are mostly meant for storing class and function declarations. Source files are the files that eventually get compiled to a program (this might not be the most accurate description, but it might allow you to ask more specific questions. Also, hopefully someone will correct me if I said anything that's inaccurate/incorrect).
include is used for two reasons: Readability and Re-usability.

Readability - By putting header and initialization code into the .h file you remove it from the .cpp file making the .cpp file cleaner, shorter, and generally easier to understand.

Re-usability - Code in a .h file can be included in multiple .cpp files without having to be re-written. This way, you can make an update to the .h file once and that change will cascade to all of the places it was included.
--Ben Finkel
http://en.wikipedia.org/wiki/Header_file
Thanks guys, this clears up so much confusion and makes me understand how everything I've read about C++ ties together.

Another question: My book is teaching me to use C++ and DirectX to do things like draw sprites on the screen and move them around, but I'm quite lost because I don't know what many of these DirectX functions are doing. I'm having trouble finding a good beginners guide / overview of functions in DirectX and Direct Input and drawing 2D sprites with Direct3D and stuff. All I can find on 2D DirectX are annoying guides from 1999 because everyone has moved onto 3D. I want to use more recent DirectX functions rather than going off of a guide that uses old versions DirectX so that my gained knowledge isn't so obsolete already.

P.S. Sorry for not putting this in the DirectX Forum instead, but since I've started this conversation topic I would rather post this extra inquiry here.

Thanks,

Brent
You can still do 2D, it was just merged into Direct3D.

Here's one tutorial on using sprites with D3D from Toymaker, which is a very detailed site to learn DirectX IMO.

This topic is closed to new replies.

Advertisement