什么语法::〜意味着在C + + Visual Studio 2010新添加的类 [英] What exactly does the syntax ::~ mean in newly added class in C++ Visual Studio 2010
问题描述
我有一个简单的问题:
情况:
当我右击Source Files文件夹并选择Add-> Class - C ++类,
a类被添加在一个单独的文件* .cpp和* .h(伟大!这正是我想要的)。
现在:函数名称
classname ::〜classname(void)
究竟是什么?
是类名为classname的析构函数吗?
我在互联网上找不到这个语法::〜的解释,所以我在这里问。 :)
这里有两种不同的工作方式:
- 命名空间定界符运算符
::
- 析构函数,它是一个特殊函数 在您的情况下,语法
classname ::〜classname(void)
只是定义类的析构函数。::
意味着以下属于classname
的类。接下来的只是析构函数名(参见上文)。
这是与所有类成员定义相同的语法。如果你的类有一个名为
foo
的函数,它接受一个int
,并返回一个int
,那么它在类外面的定义如下:
int classname :: foo b $ b
这与destructor完全相同(除了析构函数没有返回值, )。
I have s simple question:
Situation: When I rightclick Source Files folder and select Add->Class - C++ class , a class is added in a separate file *.cpp and *.h (great! This is exactly what I wanted).
Now: what does the function name
classname::~classname(void)
exactly does ?
Is it a destructor of that class called "classname" ?
I cannot find explanation of this syntax "::~" on the internet, and so I am asking here. :)
解决方案There are two different things at work here:
- The namespace delimiter operator,
::
- The destructor, which is a special function that’s always called
~classname
.
In your case, the syntax
classname::~classname(void)
simply defines the class’ destructor. The::
means that what follows belongs to the class calledclassname
. And what follows is just the destructor name (see above).This is the same syntax used for all class member definitions. If your class had a function called
foo
that took anint
and returned anint
, then its definition outside the class would look as follows:int classname::foo(int)
This is exactly the same as with the destructor (except that the destructor has no return value and takes no arguments).
这篇关于什么语法::〜意味着在C + + Visual Studio 2010新添加的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- The namespace delimiter operator,