#defines

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Quantum1982
Posts: 45
Joined: Mon Apr 23, 2012 9:31 am

#defines

Post by Quantum1982 »

Why is this not allowed ? :

Code: Select all

 
#define Empty = 0;
#define Wall = 1;
#define Movable = 2;
 
class CMazeItem
    {
    public:
            CMazeItem(void);
                        int Type;
    };
CMazeItem::CMazeItem(void)
{
        Type = Empty;
}
 
I get the following error :

error C2059: syntax error : '='

I can use enumerated types to get around this problem, but what's going on here ?
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: #defines

Post by hendu »

Your syntax is wrong.

#define Empty 0

is right. Currently it expands to Type = = 0.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: #defines

Post by CuteAlien »

For constant integers you should use "const int" instead of defines. Or use enums. Defines pollute your namespace and can lead to hard to find errors (they just replace any occurance of Empty in your code with 0 for example and if you forget at some time that you had some define for that somewhere in your code it can lead to funny results if you try to use that for example for a variable somewhere).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply