为什么我们需要括号来定义析构函数?
why do we need parentheses for destructor definition?
我知道怎么定义析构函数就是这样
~ClassName()
{
}
并且析构函数不能有参数。那为什么我们必须在class名字后面写括号呢?因为析构函数不能有参数,我认为它没有任何好处。还是它还有其他作用?
我认为如果不需要括号会更好,因为它明确说明析构函数不能有参数
~ClassName
{
}
到目前为止有两个原因
It is a function so it needs the syntax declaration of a function.
Why is the function declaration syntax like that? It's how the grammar
was defined.
在D编程语言中,当没有参数时,函数的括号是可选的。 D 旨在成为更好的 C++。您可能对该语言感兴趣 https://dlang.org/
我知道怎么定义析构函数就是这样
~ClassName()
{
}
并且析构函数不能有参数。那为什么我们必须在class名字后面写括号呢?因为析构函数不能有参数,我认为它没有任何好处。还是它还有其他作用?
我认为如果不需要括号会更好,因为它明确说明析构函数不能有参数
~ClassName
{
}
到目前为止有两个原因
It is a function so it needs the syntax declaration of a function.
Why is the function declaration syntax like that? It's how the grammar was defined.
在D编程语言中,当没有参数时,函数的括号是可选的。 D 旨在成为更好的 C++。您可能对该语言感兴趣 https://dlang.org/