在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?

请每个回答只回答一个特征。


当前回答

在c++中,创建受保护抽象虚基纯虚私有析构函数的能力。

这是从受保护的抽象虚拟基继承的纯虚拟私有析构函数。

IOW,只能由类的成员或友元调用的析构函数(private),在声明它的基类(抽象基)中赋值0(纯虚),稍后将在以受保护的方式共享多重继承基(虚基)的派生类中定义/重写它。

其他回答

我最喜欢的奇怪的C语言是5[“Hello World”],但因为已经发布了,我最喜欢的第二个奇怪的是Windows版本结构初始化黑客:

void someWindowsFunction() {
    BITMAPINFOHEADER header = {sizeof header};

    /* do stuff with header */
}

这条微妙的线条达到了以下效果:

Declares a BITMAPINFOHEADER structure Concisely sets the "size" member of the structure, without hardcoding a size constant (since many Window structures, including BITMAPINFOHEADER, follow the convention of specifying the size of the structure as the first member} Declares the version of the structure (since many Windows structures, including BITMAPINFOHEADER, identify their version by the declared size, following the convention that structures definitions are append-only) Clears all other members of the structure (a C standard behavior when a structure is incompletely initialized).

Perl中的字符串数学非常奇怪。

$ perl -E '$string = "a"; $string++; say $string'
b

$ perl -E '$string = "abc"; $string++; say $string'
abd

$ perl -E '$string = "money"; $string++; say $string'
monez

$ perl -E '$string = "money"; $string--; say $string'
-1

ruby中的隐含变量\constants和可变常量

Java的访问修饰符对我来说是最近的一个WTF(因为我必须学习一点)。

显然,包比类层次结构更亲密。我不能定义对子类可见但对包中的其他类不可见的方法和属性。为什么我要将一个类的内部共享给其他类呢?

但是我可以定义对包内的每个类可见的属性和方法,但对包外的子类不可见。

不管我怎么想,我还是看不出其中的逻辑。切换访问修饰符,使受保护的行为就像它在c++中工作一样,并保持包的私有修饰符,这是有意义的。但现在不是了。

在Java中:

int[] numbers() {
  return null;
}

可以写成:

int numbers() [] {
  return null;
}