簡體   English   中英

功能之間未解決的外部因素

[英]Unresolved Externals between functions

我遇到了無法解決的外部錯誤,但我無法弄清楚到底是什么原因引起的。

error LNK2019: unresolved external symbol "public: __thiscall ABC::ABC(class ABC const &)" (??0ABC@@QAE@ABV0@@Z) referenced in function "public: __thiscall hasDMA::hasDMA(class hasDMA const &)" (??0hasDMA@@QAE@ABV0@@Z)

1> C:\\ Users \\ Matt \\ documents \\ Visual Studio 2010 \\ Projects \\ GSP_125_Lab5 \\ Debug \\ GSP_125_Lab5.exe:致命錯誤LNK1120:1無法解析的外部

當我刪除以下代碼塊時,程序將運行:

hasDMA::hasDMA(const hasDMA & hs) : ABC(hs)
{
    style = new char[std::strlen(hs.style) + 1];
    std::strcpy(style, hs.style);
}

但我不知道其中的哪一部分被其他地方引用。

這是我的ABC標頭和hasDMA標頭。

class ABC
{
private:
    enum {MAX = 35};
    char label[MAX];
    int rating;
protected:
    const char * Label() const {return label;}
    int Rating() const {return rating;}
public:
    ABC(const char * l = "null", int r = 0);
    ABC(const ABC & rs);
    virtual ~ABC() {};
    virtual ABC & operator*()  { return *this; }
    ABC & operator=(const ABC & rs);
    virtual void View() const = 0;
    friend std::ostream & operator<<(std::ostream & os, const ABC & rs);
};


class hasDMA :public ABC
{
private:
    char * style;
public:
    hasDMA(const char * s = "none", const char * l = "null",
              int r = 0);
    hasDMA(const char * s, const ABC & rs);
    hasDMA(const hasDMA & hs);
    ~hasDMA(){};
    hasDMA & operator=(const hasDMA & rs);
    virtual void View() const;
};

這些是我僅有的兩種ABC方法:

ABC::ABC(const char *l, int r)
{
    std::strcpy(label, l);
    label[MAX - 1] = '\0';
    rating = r;
}

ABC & ABC::operator=(const ABC & rs)
{
    if (this == &rs)
        return *this;

    strcpy(label, rs.label);

    return *this;
}

如果有幫助,這些是我的hasDMA方法的其余部分:

hasDMA::hasDMA(const char *s, const char *l, int r) : ABC (l, r)
{
    std::strcpy(style, s);
}

hasDMA::hasDMA(const char *s, const ABC & rs)
{
    std::strcpy(style, s);
}

void hasDMA::View() const
{
    cout << "Record Label: " << Label() << endl;
    cout << "Rating: " << Rating() << endl;
    cout << "Style: " << style << endl;

}

hasDMA & hasDMA::operator=(const hasDMA & hs)
{
    if (this == &hs)
        return *this;

    ABC::operator=(hs);
    style = new char[std::strlen(hs.style) +1];
    std::strcpy(style, hs.style);

    return *this;
}

您已經聲明了ABC復制構造函數,但尚未定義它。

ABC(const ABC & rs); // declaration. 

您將需要提供定義或刪除聲明。

通過使用std::string而不是char數組,可以大大簡化類。 您不需要提供賦值運算符,復制構造函數或析構函數。

您忘記定義ABC(const ABC&rs)的實現;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM