函数之间的未解析外部
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:\用户\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] = ' ';
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) 定义实现;
相关文章:
- C++中std::resize(n)和std::shrink_to_fit之间的区别
- int(c) 和 c-'0' 之间的区别。C++
- 类内部和外部静态 constexpr 元组之间的差异
- 在 typedef 内部使用 const 关键字和在 typedef 外部使用 const 关键字之间有区别吗?
- Visual Studio 中静态库项目之间的未解析外部
- 匹配外部单引号之间的字符串
- 在没有外部文件的情况下在应用会话之间保存变量
- 无法将Android WebView渲染到C 和Java代码之间共享的外部纹理中
- 如果用像素来给出两条线(外部和内部)之间的边缘(外部和内部)之间的边缘,则如何计算(x,y)坐标
- 内部和外部过载C++运算符之间的差异
- 在内部和外部与调试器之间运行有什么区别
- dll和应用程序之间的C++外部使用
- 外部"C"和简单的外部之间的区别
- 相同的外部结构只有一个功能之间的区别
- decltype和隐藏外部名称的类成员名称之间的交互
- c++主外部函数之间的共享列表
- 在类之间共享向量时,无法解析的外部符号向量
- 我可以在两个OpenGL上下文之间共享外部纹理吗?
- 在类定义内部和外部定义成员函数之间有区别吗
- 函数之间的未解析外部