Thread: Header inclusion causing errors

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    38

    Header inclusion causing errors

    I am modifying a file in a large c++ software program. I need to "#include" a data class into the header of the file I am working with, but when I do that (and compile) I get a ton of "syntax" errors. I went back through all the other header files and added the "guards":
    Code:
    #ifndef HEADERNAME_H
    #define HEADERNAME_H
    // all code
    #endif
    but i still get these errors. If I comment out the new #included class, everything runs fine. Does anyone have any ideas as to what could be the problem?

    Thanks
    chris

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    What exactly are the syntax errors that you are getting? Your header protection looks ok to me. I personally use this method
    Code:
    #ifndef _headerName_h
    #define _headerName_h
    //code
    #endif
    Woop?

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Quote Originally Posted by prog-bman
    What exactly are the syntax errors that you are getting? Your header protection looks ok to me. I personally use this method
    Code:
    #ifndef _headerName_h
    #define _headerName_h
    //code
    #endif
    Convention dictates that anything beginning with _ is reserved for the compiler and that macros are to be all uppercase

  4. #4
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Oh really did not know that thank you thantos
    Woop?

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    38
    syntax errors look like this:
    Code:
     error C2061: syntax error : identifier 'HeaderName'
    and I get about 500 of them. "HeaderName" is the class that I am modifying and added the new "#include" class to
    chris

  6. #6
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    So you don't get these errors when you you don't include the header file? If thats the case i would look into the header file and see if there is something fishy about your code there
    Woop?

  7. #7
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Post some of the code (the header, perhaps). If it isn't inclusion guards, then it's difficult to tell what's amiss without seeing some of the code.

  8. #8
    Registered User
    Join Date
    May 2003
    Posts
    38
    This particular header file has be "#included" else where without any problems. But I will check. I feel like this is the type of error that occurs when there are "multiple inclusions" of the same header file...but supposedly the "#ifndef" should avoid that problem...right...
    chris

  9. #9
    Registered User
    Join Date
    May 2003
    Posts
    38
    I'm not sure if this is going to do much good but there is the header file that, when included, causes problems.
    Code:
    #ifndef METAINTENT_H
    #define METAINTENT_H
    
    #include"MetaIntentObject.h"
    #include"FisbData.h"
    #include"IntentModels.h"
    
    // META INTENT MODEL ID's
    const int FLY_TCP_LIST = 0;			// fly the tcp list
    const int DIRECT2_TCP1 = 1;			// direct to tcp+1
    const int DIRECT2_TCP2 = 2;			// direct to next tcp+2
    const int AVOID_WX_R2FP = 3;		// avoid weather and return to flight path
    const int AVOID_WX_R2FP_TURN = 4;	// avoid weather and return to flight path WITH TURN
    const int AVOID_SUA_R2FP = 5;		// avoid sua and return to flight path 
    const int AVOID_SUA_R2FP_TURN = 6;	// avoid sua and return to flight path WITH TURN
    const int RETURN2FP_TCPLIST = 7;	// 45 degree intercept then continue on the flight path
    const int LAND_AT_AIRPORT = 8;		// Assumes use of the 3:1 ration rule to land at an airport
    const int HOLDING_PATTERN_LF = 9;	// Aircraft is flying a holding pattern LEFT(prediction ??)
    const int HOLDING_PATTERN_RT = 10;	// Aircraft is flying a holding pattern RIGHT(prediction ??)
    const int BLUNDERING_H_LF = 11;		// Aircraft is blundering horizontally
    const int BLUNDERING_H_RT = 12;		// Aircraft is blundering horizontally
    const int BLUNDERING_H = 13;		// Aircraft is blundering horizontally
    const int DIRECT_TO_TCP = 14;		// just like FLY_TCP_LIST but outside of RNP
    
    const int META_INTENT_COUNT = 15;
    
    class MetaIntent {
    
    private:
    
    	MetaIntentObject metaIntentObj[META_INTENT_COUNT];		// instance of the meta intent object
    
    public:
    
    	MetaIntent(void);
    	~MetaIntent(void);
    	
    	void initialize();
    	void start(FlightClass*, int);
    	void supervisor(FlightClass*, FisbData*);
    	void metaPrediction(FlightClass*, int, FisbData*);
    	int getWinningMetaID(void);
    
    	MetaIntentObject* getMetaIntentByNum(int);
    	int getFirstTCPOutsideOfRegion(FlightClass*, double*, double*,int,int,int);
    	int getFirstTCPInfrontOfAc(FlightClass*, int);
    
    	void printOutputFile(void);
    	void closeFile(void);
    
    };
    
    #endif
    chris

  10. #10
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Check the files that you are including in that header maybe one of them is already including another header eg maybe intentModals is already including FisbData
    Woop?

  11. #11
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>error C2061: syntax error : identifier 'HeaderName'

    Just a quick check, to make sure the problem isn't something really silly:
    1) You don't have any other errors or warnings before these ones, right?
    2) By 'HeaderName' you mean "MetaIntent.h" right?
    3) The file IS called MetaIntent.h on the harddrive, and that isn't just how it appears in your IDE, right?

    If all of the above is correct:
    Check all the headers included in MetaIntent.h (MetaIntentObject.h, FisbData.h, IntentModels.h) and make sure that after each class declaration you haven't forgotten the semicolon. If that's all ok, check and make sure all of the syntax in the other headers is correct.

    **EDIT**
    >>maybe one of them is already including another header
    Header inclusion guards should eliminate any problems from that, unless of course you've got a typo in one of the inclusion guards.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  12. #12
    Registered User
    Join Date
    May 2003
    Posts
    38
    I apprieciate everyone help. And I am looking into everything that has been suggested, but I want to make a quick clarification with the class names and the error message that I am getting. The class above is the "MetaIntent" class. This is the class that when "#included" into the class that I am modifying (lets call that class "Class2") is causing all the errors. But the errors do not complain about the "MetaIntent" class, then complain about the class (header) that I am modifying. So the message looks like the following:
    Code:
    error C2061: syntax error : identifier 'Class2'
    Also, Class2 is a pretty common class and is included in a lot of files.
    chris

  13. #13
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Interesting. Say, do you happen to use any instances of Class2 in MetaIntent? And is MetaIntent included anywhere else? Because if Class2 is used in MetaIntent then in MetaIntent you probably need to #include "Class2.h" (and that's where you need the header inclusion guards - to prevent an infinite loop).
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Many Header Files
    By matth in forum C++ Programming
    Replies: 3
    Last Post: 03-08-2005, 02:45 PM
  2. question about .net to 6.0 change causing errors
    By jverkoey in forum C++ Programming
    Replies: 17
    Last Post: 03-23-2004, 10:45 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Flood of errors when include .h
    By erik2004 in forum C++ Programming
    Replies: 14
    Last Post: 12-07-2002, 07:37 AM
  5. Using c++ standards
    By subdene in forum C++ Programming
    Replies: 4
    Last Post: 06-06-2002, 09:15 AM