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

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


当前回答

c++最恼人的解析:

struct S
{
    S() {} //default constructor
};

int main() {

    S s(); // this is not a default construction, it declares a function named s that takes no arguments and returns S.
}

其他回答

在C中,a[b][C]与C [b[a]]完全相同。

在PHP中,字符串和函数指针一样好:

$x = "foo";
function foo(){ echo "wtf"; }
$x(); # "wtf"

不幸的是,这并不管用:

"foo"();

我曾经写过一种编程语言,它有一个“strfry”操作符:

"hello world"?
# => "wdo rlholle"

有用的,是吗?

VBScript的日期/时间文字(为什么这个仍然如此罕见?):

mydate = #1/2/2010 5:23 PM#

If mydate > #1/1/2010 17:00# Then ' ...

编辑:日期文字是相对的(那么它们在技术上是文字吗?):

mydate = #Jan 3# ' Jan 3 of the current year

VB。NET,因为它是编译的,所以不支持相对日期文字。只支持日期或时间字面量,但缺失的时间或日期被假定为零。

编辑[2]:当然,有一些奇怪的极端情况会出现相对日期……

mydate = #Feb 29# ' executed on 2010-01-05, yields 2/1/2029

在我看来,这在c++中是不允许的:

class A {
public:
  virtual string foo(){return "A::foo";}
};

class B : public A {
public:
  virtual string foo(){return "B::foo";}
};

int main () {
  B* b = new B();
  // In my opinion the following should not be allowed
  cout << b->A::foo() << endl;  // Will print "A::foo"
}

这似乎是正确的,但这意味着如果不允许子类的用户调用原始方法而不是新方法,就不能重写方法。

只要考虑一个集合的子类,当向集合本身添加一个元素时,您希望增加元素的数量。

一个合乎逻辑的解决方案是重写add()方法,在添加元素之前增加计数器,但是新集合的用户可以使用旧方法向其添加元素,这样就绕过了增量,导致元素计数器与集合的实际元素数量不一致。

这在Java中是不可能的。