为什么调用带有未声明变量的仿函数有效?

Why does calling a functor with an undeclared variable work?

class foo {
    public:
    bool operator () (int & i) {
        return true;
    }
};

int main() {
    foo(WhyDoesThisCompile);
    return 0;
}

当将 WhyDoesThisCompile(没有空格)传递给仿函数时,程序会编译。

这是为什么?我在 clang 4.0.0.

上测试过

您没有调用仿函数。

您正在声明一个名为 WhyDoesThisCompilefoo

是的,尽管有括号。


我猜你是这个意思:

   foo()(WhyDoesThisCompile);
// ^^^^^
// temp ^^^^^^^^^^^^^^^^^^^^
//  of   invocation of op()
// type
// `foo`

…这不是。