类析构函数符号出了什么问题?在vc++中
What wrong with class destructor symbol ? in vc++
这是我的代码:
#include <iostream>
using namespace std;
class new_class{
public:
new_class();
float multiplication(){return x*y;}
~new_class();
private:
float x;
float y;
};
int main()
{ new_class class_11;
cout<<class_11.multiplication()<<endl;
system("pause");
return 0;
}
错误日志:
Main.obj : error LNK2001: unresolved external symbol "public: __thiscall new_class::~new_class(void)" (??1new_class@@QAE@XZ)
Main.obj : error LNK2001: unresolved external symbol "public: __thiscall new_class::new_class(void)" (??0new_class@@QAE@XZ)
我正在使用Visual studio 2010,Visual c++有人能解释我吗我做错了什么
您还没有定义您的构造函数或析构函数,您只是声明了它们。
程序中使用的任何函数都必须在某个地方定义。函数定义由函数声明及其定义组成。例如,您的multiplication
成员函数定义为:
float multiplication() { return x * y; }
^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^
function declaration this makes the declaration a definition
"未解析的外部符号"错误意味着编译器找到了函数的声明,但链接器找不到定义。因此,您需要为链接器指出的两个函数提供定义:默认构造函数和您声明的析构函数。
也就是说,请注意,如果您没有声明任何构造函数,编译器将隐式地为您的类提供默认构造函数,这通常就足够了。如果不声明析构函数,编译器将隐式提供析构函数。所以,除非你真的需要在构造函数或析构函数中做一些事情,否则你不需要自己声明和定义它们。
确保你有一本很好的C++入门书。这本书将更详细地介绍如何定义成员函数,以及编写构造函数和析构函数的最佳实践(正确编写析构函数充满危险(。
您应该实现析构函数,您刚刚将其声明为
相关文章:
- 警告处理为错误这里有什么问题
- 最小硬币更换问题(自上而下方法)
- 为"adjacent"变量赋值时出现问题
- 我的神经网络不起作用 [XOR 问题]
- 在Ubuntu 16.04上安装Cilk时出现问题
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 编译包含字符串的代码时遇到问题
- Project Euler问题4的错误解决方案
- 问题:什么是QAbstractItemView::NoEditTriggers的反面
- 在VC++中从DLLMAIN内部调用D3D的CREATEDEVICE时,它会创建一个死锁(loaderlock?)。有没有办法克服这个问题?最终目标内
- VC++使用gumbo查询时出现问题(链接错误)
- 如何在VC++6.0上解决这个问题
- 如何将双精度数组从 VB6 传递到 VC++.这段代码有什么问题
- 文件打开问题,删除文件后.在VC++中fopen状态失败
- 编译在VC ++中查找,但G ++在链接时'undefined reference'问题。
- 从VC++目录切换到Boost的用户宏时出现问题
- vc++ mfc 中的串行编程存在一些问题
- 在 VC++ MFC 中使用静态变量时出现问题
- 类析构函数符号出了什么问题?在vc++中
- 性能问题与c++(使用vc++ 2010):在运行时,我的程序似乎随机等待一段时间