Just need help understanding something :)

Started by
2 comments, last by Dko 20 years, 5 months ago
Ok im getting good at C++, I can code a windows window, I can puta 3d cube via directx in it but there are still some basic things that kick my butt when I look at them in someone elses code. So what I ask is simple what the heck is up with this stuff. -Like this(I know define is a lot like const, but why they heck is this name so freagin long) #if !defined(AFX_GAME_H__687221F3_ACFF_4D66_97DB_88AB70E0CA59__INCLUDED_) #define AFX_GAME_H__687221F3_ACFF_4D66_97DB_88AB70E0CA59__INCLUDED_ -And this(This just hurts my little brain ) #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000
Advertisement
The first one, !define(AFX_GAME ... ) is randomly generated to make sure you don't have multiple instances of the same file.

Ok, both of these things have to do with multiple including of files.

Lets say you only want to compile something once, but you want multiple things to view it. Well, unless you put your .h exactly in the right place, you're screwed. A way to get around it is use #defines.


#ifndef AFX_GAME_H
#define AFX_GAME_H

makes sure you only run AFX_GAME_H once, and if your compiler has a AFX_GAME_H, then it won't compile the .h file again.


You can cheat with a non-standard #pragma, called #pragma once. That will make sure your files are only included once. Of course, it is only avalible on MSVC over verson 1000. To make sure MSVC doesn't use it, you get the second piece of code.

Sorry, its a bit confusing until you start on a big project, then you'll love them. :D
~~~~~
"Sorry(dede), I'm only 22 years old. But I WOULD kill you if I see you around " - pouya.
Download and play Slime King I.


[edited by - dede on October 23, 2003 2:25:31 AM]
~~~~~Screaming Statue Software. | OpenGL FontLibWhy does Data talk to the computer? Surely he's Wi-Fi enabled... - phaseburn
Ahh I understand now. thanks
Yes, I went through hell trying to figure out what was wrong with my include files until I learned about the beautiful statements #ifndef, #define, and #endif.

This topic is closed to new replies.

Advertisement