为什么用未申报的变量工作调用函子

Why does calling a functor with an undeclared variable work?

本文关键字:工作 调用 变量 为什么      更新时间:2023-10-16
class foo {
    public:
    bool operator () (int & i) {
        return true;
    }
};
int main() {
    foo(WhyDoesThisCompile);
    return 0;
}

WhyDoesThisCompile(无空间(传递给函子时,程序会编译。

为什么?我在clang 4.0.0中进行了测试。

您不调用函数。

您正在声明foo,称为WhyDoesThisCompile

是,尽管有括号。


我想你的意思是:

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

…不是。

相关文章: