Я получаю нерешенную внешнюю ошибку, но я не могу понять, что именно вызывает ее.
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);