Like Tree1Likes
  • 1 Post By laserlight

"Extra tokens at end of #ifndef directive"

This is a discussion on "Extra tokens at end of #ifndef directive" within the C++ Programming forums, part of the General Programming Boards category; This is probably something really stupid that I fail to see, but as I jsut said I am failing at ...

  1. #1
    Your imaginary friend
    Join Date
    Jan 2010
    Location
    Canada
    Posts
    75

    "Extra tokens at end of #ifndef directive"

    This is probably something really stupid that I fail to see, but as I jsut said I am failing at seeing it...

    So I keep getting the error "Extra tokens at end of #ifndef directive" in the following code

    Code:
    #ifndef OBJECT_WEAPON-EXTENSION_H_INCLUDED
    #define OBJECT_WEAPON-EXTENSION_H_INCLUDED
    
    #include <sstream>
    
    #include "OBJECT_Handler.h"
    
    class WEAPON : protected OBJECT{
    	public:
    		WEAPON(std::string, int, int, int, int, int, int, int, int, int, int);
    
    	private:
    		int TYPE;
    		int ATTACK;
    		int DEFENCE;
    		int AGILITY;
    		int SPEED;
    		int INTELLIGENCE;
    		int EFFECT[3];
    };
    
    #endif // OBJECT_WEAPON-EXTENSION_H_INCLUDED
    and for good measure here is OBJECT_Handler.h
    Code:
    #ifndef OBJECT_HANDLER_H_INCLUDED
    #define OBJECT_HANDLER_H_INCLUDED
    
    #include <sstream>
    
    class OBJECT{
    	public:
    		OBJECT(std::string, int);
    
    	protected:
    		std::string NAME;
    		unsigned int ID;
    };
    
    #endif // OBJECT_HANDLER_H_INCLUDED

  2. #2
    Registered User
    Join Date
    Apr 2006
    Posts
    2,009
    You can't put '-' in an identifier. So 'OBJECT_WEAPON-EXTENSION_H_INCLUDED' doesn't work. You need to change it to not contain '-'
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  3. #3
    Your imaginary friend
    Join Date
    Jan 2010
    Location
    Canada
    Posts
    75
    Code::Blocks made that part for me, never thought that it would make such a thing possible, thanks for the help!

  4. #4
    Your imaginary friend
    Join Date
    Jan 2010
    Location
    Canada
    Posts
    75
    Most probably something stupid again, but I've reread it 50 times, and rewrote it jsut about as many times, using all three loop types...

    If the Character's health goes under 0, the IsAlive bool is set to false.
    Get_Attack returns -4, exactly as expected, but after a few iterations of the loop(aka when the enemy Mob_CHARA should die the health goes all the way back up to full health. Anyone have any ideas why?

    Code:
    void ENGINE::BATTLE(PLAYER User_CHARA, MONSTER Mob_CHARA){
    	bool BATTLE_OVER = false;
    	while(BATTLE_OVER == false){
    		User_CHARA.Display_Info();
    		Mob_CHARA.Display_Info();
    		Mob_CHARA.Set_HEALTH(User_CHARA.GET_ATTACK());
    		std::cin.get();
    		if(Mob_CHARA.IsAlive != true){BATTLE_OVER = true;}
    		else if(User_CHARA.IsAlive != true){BATTLE_OVER = true;}
    	}
    }
    EDIT: never knew unsigned ints going into negatives were handled so badly... Anyways figured it out
    Last edited by jerimo; 12-16-2012 at 09:54 PM.

  5. #5
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    404
    What's the code look like in the set_HEALTH() function?

    Also a small tip
    Code:
     
    while(BATTLE_OVER == false)
    Can be reduced to
    Code:
    while(!BATTLE_OVER)
    Same can be done with your ifs. As far as the error its not apparent to me in this code but its probably in the only function that seems to adjust health.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,955
    This is not Eiffel, so I suggest that you reserve fully capitalised names for macro names, or at least for named constants. For example, you could consider renaming ENGINE to Engine, PLAYER to Player, MONSTER to Monster. BATTLE could just be battle, and why write User_CHARA when you could writer user_character or even just user? Likewise, BATTLE_OVER is a flag, not a constant, so just write battle_over.

    Anyway, we can simplify your code to:
    Code:
    void ENGINE::BATTLE(PLAYER User_CHARA, MONSTER Mob_CHARA) {
        bool BATTLE_OVER = false;
        while (!BATTLE_OVER) {
            User_CHARA.Display_Info();
            Mob_CHARA.Display_Info();
            Mob_CHARA.Set_HEALTH(User_CHARA.GET_ATTACK());
            std::cin.get();
            if (!Mob_CHARA.IsAlive || !User_CHARA.IsAlive) {
                BATTLE_OVER = true;
            }
        }
    }
    or even:
    Code:
    void ENGINE::BATTLE(PLAYER User_CHARA, MONSTER Mob_CHARA) {
        do {
            User_CHARA.Display_Info();
            Mob_CHARA.Display_Info();
            Mob_CHARA.Set_HEALTH(User_CHARA.GET_ATTACK());
            std::cin.get();
        } while (Mob_CHARA.IsAlive && User_CHARA.IsAlive);
    }
    However, this in itself is unlikely to fix your problem. It sounds like the problem lies elsewhere in the code, e.g., related to the get attack and set health functions.

    EDIT:
    EDIT: never knew unsigned ints going into negatives were handled so badly... Anyways figured it out
    Ah, good to see that you fixed your problem. However, it is not true that "unsigned ints going into negatives were handled so badly", unless you mean to say that you handled them badly
    Last edited by laserlight; 12-16-2012 at 09:58 PM.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Your imaginary friend
    Join Date
    Jan 2010
    Location
    Canada
    Posts
    75
    Well form what I saw I didn't do jack squat badly with them but if they go into negatives they boost up to the highest possible value that they can reach and complete the substraction. So if the number did not reach an exact zero, it would boost up to huge numbers be braught back down to MAX_HEALTH (in this exact case 99) and the loop would not end as it would not actually ever reach < 0. FIxed it by checking to see if negative change was greater than health, if so health is equal to zero, which fires the if statement that makes IsAlive false, and the loop can now end. All this because of a weird thing that I never knew about; Oh well now I learned!

  8. #8
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,639
    Unless you have some really compelling reason to do this the way you are doing it, you need to adopt a more standard C++ naming style. All capital letters are typically reserved for constants, not used for variable, class or method names. This is because they're pretty difficult to read, and making constants all-caps allows these special values to stick out in your code.

    Here's one from Google, here's Wikipedia; feel free to delve into further research, as there's no shortage of opinions on the subject. Just be sure to pick one and be consistent.

  9. #9
    Your imaginary friend
    Join Date
    Jan 2010
    Location
    Canada
    Posts
    75
    I don't have any reason other than, i like the look of it that way. I'm sure it doesn't fit many people but it works for me, and truly it's either that or total spaghetti... If I follow the "normal" way I always get lost and end up making bull..........

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,955
    Well, if you are just coding for yourself to read, then sure. But if you're coding in a team, or posting code here, then using unusual stylistic conventions will merely serve to confuse your readers and distract them from the actual matter at hand.
    King Mir likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 04-26-2009, 05:59 AM
  2. Warning on an ifndef directive
    By DavidP in forum C++ Programming
    Replies: 2
    Last Post: 08-02-2007, 01:31 AM
  3. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 07:25 AM
  4. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 06:59 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21