:~的含义是什么
What is the meaning of ::~
本文关键字:是什么 更新时间:2023-10-16
在以下代码中,以下内容的含义是什么::~
GaussianMex::~GaussianMex()
{
int i;
}
这不是单个运算符::~
,而是GaussianMex析构函数的定义。通过ClassName::ClassMethod
语法定义类方法,由于析构函数名称为~ClassName
,因此析构函数定义为ClassName::~ClassName
。
这是一个析构函数。
考虑:
class GaussianMex
{
public:
// This is the CONstructor (ctor). It is called when an instance of the class is created
GaussianMex()
{
};
// This is a Copy constructor (cctor). It is used when copying an object.
GaussianMex(const GaussianMex& rhs)
{
};
// This is a move constructor. It used when moving an object!
GaussianMex(GaussianMex&& rhs)
{
};
// This is the DEStructor. It is called when an instance is destroyed.
~GaussianMex()
{
};
// This is an assignment operator. It is called when "this" instance is assigned
// to another instance.
GaussianMex& operator = (const GaussianMex& rhs)
{
return *this;
};
// This is used to swap two instances of GaussianMex with one another.
friend void swap(GaussianMex& lhs, GaussianMex& rhs)
{
};
}; // eo class GuassianMex
构造函数的目的是进行所需的任何初始化(可能是分配内存或其他类实例)。析构函数的作用正好相反——它对类在其生存期内分配的任何资源进行清理。
表示该方法是一个析构函数。
类最多可以有一个析构函数,并且它总是以~
符号为前缀的类名。
只要对象的实例被销毁,就会调用析构函数。每当实例超出作用域,或者在指向类实例的指针上调用delete
时,就会发生这种情况。
您正在定义类GaussianMex
的析构函数。
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- C++避免重复声明的语法是什么
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 实现无开销push_back的最佳方法是什么
- C++从另一个类访问公共静态向量的正确方法是什么
- "throw expression code" 1e7 >返回 d 是什么?投掷标准::overflow_error( "too big" ) : d;意味 着?
- C++中名称篡改的目的是什么
- 在 c++ 中拥有一组结构的正确方法是什么?
- 这个指针和内存代码打印是什么?我不知道是打印垃圾还是如何打印我需要的值
- 是什么阻止DOMTimerCoordinator::NextID进入无休止的循环
- 派生类销毁的最佳实践是什么
- 这个语法std::class<>{}(arg1, arg2) 在C++中是什么意思?
- 通过JNI传递数据数组的最快方法是什么
- "using namespace std;"在C++的作用是什么?
- 在两台机器之间进行时间戳的最佳c++chrono函数是什么
- 文件系统:复制功能的速度秘诀是什么
- 用常见虚拟函数实现的任意组合来实现派生类的正确方法是什么
- 使用QQuickFramebufferObject时同步数据的最佳方式是什么
- 是什么原因导致它无法编译?它是声明签名还是在函数本身的实现中
- 使用不同的CRT将新的C++代码与旧的(二进制)组件隔离开来的最佳方法是什么