Jump to content
  • Advertisement
Sign in to follow this  
eltharynd

include guards for large projects

This topic is 2121 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

does any of you have any tutorial for this?

I'm working on a very large project and every time i add a class i get 12157906125 compile errors.

 

every .h is guarded AND every #include is re-guarded and sometimes i have to use forward declaration but still I got problems....

Now I've been stuck half an hour since the last time i created the last file:

#ifndef __SPRITE_H__
#define __SPRITE_H__
#ifndef __OBJECT_H__
#include "Object.h"
#endif

class Sprite: public Object
{
/////CODE
};

#endif

i tried to play a little with the guard by removing them but nothing to do... 

Error 29 error C2504: 'Object' : base class undefined c:\users\eltharynd\documents\visual studio 2012\projects\space\space\sprite.h 9 1 Space
 
please help me...

Share this post


Link to post
Share on other sites
Advertisement

pragma once is actually something I seem to have forgotten to mention. Unless one has to worry about obscure or outdated compilers, I'd always prefer that over the ifndef/define mess. Not just for potential optimizations, but because it's also less error prone in a copy/paste-happy environment (forget to update the include guard and figure out where all the weird errors are coming from).

Share this post


Link to post
Share on other sites

This is especially true when your includes start looking like

#ifndef SOMEPROJNAME_SOMENAMESPACE_SOMEOTHERNAMESPACE_qzrt8Agk17L_H_
#define SOMEPROJNAME_SOMENAMESPACE_SOMEOTHERNAMESPACE_qzrt8Agk17L_H_

//stuff

#endif

Slightly exaggerated.  ...Slightly.

 

Edit:  On that note, OP, it's generally bad practice to prefix anything with an underscore, or have any double underscores at all in user-defined stuff.

Edited by SeraphLance

Share this post


Link to post
Share on other sites
According to Wikipedia it's fairly widespread. For normal situations relying just on #pragma once should be enough, although I'm not sure how things would look on consoles. I have no real interest nor experience in that area but at least in the past some of the (so-called) C++ compilers used there were very minimalistic.

Share this post


Link to post
Share on other sites

In the past, consoles have had dodgey C++ compilers (as have most embedded devices), but these days they'd likely have just as much C++11 support as their desktop counterparts.

 

Despite this history, even the old ones still supported pragma once. I don't know of any compiler that doesnt tongue.png

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!