Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Just need help understanding something :)

This topic is 5527 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post

Link to post
Share on other sites
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]

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!