struct redefinition problem



  • Warum geht dass nicht, ich wollte einen Header speziellen Header einführen für Datentypen die ich selbst erfunden habe:

    networking_data_types.hpp

    #include <string>
    
    struct datum
    {
        unsigned long year;
        unsigned long month;
        unsigned long day;
    };
    
    struct finance
    {
        std::string money_re;
        unsigned long money_amount;
        datum money_date;
    };
    

    Und dann hab ich halt überall "networking_data_types.hpp" inkludiert wo ich die Datentypen in meinem code verwenden wollte.
    Doch kommt nur imemr n blöder Error:

    Project : Console application
    Compiler : GNU GCC Compiler (called directly)
    Directory : H:\C++ Projekte\Finanzplaner CB\
    --------------------------------------------------------------------------------
    Switching to target: default
    Compiling: main.cpp
    In file included from outgo.hpp:4,
    from main.cpp:2:
    networking_data_types.hpp:4: error: redefinition of struct datum' networking\_data\_types.hpp:4: error: previous definition ofstruct datum'
    networking_data_types.hpp:11: error: redefinition of struct finance' networking\_data\_types.hpp:11: error: previous definition ofstruct finance'
    Process terminated with status 1 (0 minutes, 0 seconds)

    MfG
    Stromberg


  • Mod

    include guards



  • #ifndef _NETWORKING_DATA_TYPES_H_ 
    #define _NETWORKING_DATA_TYPES_H_ 
    
    #include <string>
    struct datum
    {
        unsigned long year;
        unsigned long month;
        unsigned long day;
    };
    
    struct finance
    {
        std::string money_re;
        unsigned long money_amount;
        datum money_date;
    };
    #endif // _NETWORKING_DATA_TYPES_H_
    

Anmelden zum Antworten