error LNK2005: already defined



  • Hi!
    Ich habe da ein Problem mit meiner Klasse und zwar bekomm ich beim Kompilieren folgende Fehler:

    FriskyDlg.obj : error LNK2005: "public: int __thiscall Cat::GetAge(void)" (?GetAge@Cat@@QAEHXZ) already defined in FriskyCat.obj
    FriskyDlg.obj : error LNK2005: "public: int __thiscall Cat::GetWeight(void)" (?GetWeight@Cat@@QAEHXZ) already defined in FriskyCat.obj
    FriskyDlg.obj : error LNK2005: "public: void __thiscall Cat::SetAge(int)" (?SetAge@Cat@@QAEXH@Z) already defined in FriskyCat.obj
    FriskyDlg.obj : error LNK2005: "public: void __thiscall Cat::SetWeight(int)" (?SetWeight@Cat@@QAEXH@Z) already defined in FriskyCat.obj
    FriskyDlg.obj : error LNK2005: "class Cat Frisky" (?Frisky@@3VCat@@A) already defined in FriskyCat.obj
    Debug/Frisky.exe : fatal error LNK1169: one or more multiply defined symbols found

    Mein Klassenheader heißt "FriskyCat.h". Dort steht folgendes Drinn:

    #ifndef FriskyCat_h
    #define FriskyCat_h
    
    class Cat
    {
    public:
        int GetAge();
        int GetWeight();
    
        void SetAge(int age) ;
        void SetWeight(int weight);
    
    private:
        int itsAge;
        int itsWeight;
    };
    
    #endif
    

    In der dazugehörigen "Frisky.cpp" steht:

    #include "stdafx.h"
    #include "FriskyCat.h"
    
    Cat Frisky;
    
    int Cat::GetAge()
    {
        return itsAge;
    }
    
    int Cat::GetWeight()
    {
        return itsWeight;
    }
    
    void Cat::SetAge(int age)
    {
        itsAge = age;
    }
    
    void Cat::SetWeight(int weight)
    {
        itsWeight = weight;
    }
    

    Ich habe eine Dialogfeldbasierte MFC anwendung (FriskyDlg) in die ich die FriskyCat.cpp inkludiert habe.
    Mein Ziel ist es, das ich in der FriskyDlg.cpp mit GetAge() und GetWeight() auf das Alter und Gewicht der Katze zugreifen kann.

    Ich bin mir ziemlich sicher, das ich alles nur einmal Definiert habe.
    Diese include-guards funktionieren bei mir auch nicht. Was mache ich falsch? Unter Dos funktioniert alles, nur mit MFC nicht???

    Danke im Vorraus



  • FriskyCat.h statt FriskyCat.cpp einbinden.


Anmelden zum Antworten