I'm getting an unresolved external error but I can't figure out exactly what's causing it.
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 : fatal error LNK1120: 1 unresolved externals
The program runs when I delete this block of code:
hasDMA::hasDMA(const hasDMA & hs) : ABC(hs)
{
style = new char[std::strlen(hs.style) + 1];
std::strcpy(style, hs.style);
}
But I don't know what part of that is being referenced elsewhere.
Here is my ABC header and hasDMA header.
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;
};
These are the only two ABC methods I have:
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;
}
If it helps these are the rest of my hasDMA methods:
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;
}
You have declared an ABC
copy constructor, but you haven't defined it.
ABC(const ABC & rs); // declaration.
You will need to provide a definition, or remove the declaration.
You could greatly simplify the class by using an std::string
instead of the char
array. You wouldn't need to provide an assignment operator, copy constructor or destructor.