Multiple Definition (LNK2005) errors

前端 未结 3 1019
难免孤独
难免孤独 2020-12-12 07:21

I recently tried to create a global header file which would have all definitions of error codes (i.e. NO_ERROR, SDL_SCREEN_FLIP_ERROR, etc.) these would just be integers whi

3条回答
  •  长情又很酷
    2020-12-12 08:17

    using #ifndef works fine.(Although it works, this is not best practice). try like this:

    globals.h

    #ifndef GLOBALS
    #define GLOBALS
    
    int SCREEN_LOAD_ERROR = 1;
    int NO_ERROR = 0;
    
    #endif
    

    cTile.h:

    #include "globals.h"
    
    class cTile {
    };
    

    main.cpp:

    #include "globals.h"
    #include "cTile.h"
    /* rest of the code */
    

提交回复
热议问题