12
|
Tom Crockett · 技术社区 · 14 年前 |
1
11
我的直觉是,这是因为规范中的以下陈述,第6.11条,块:
And a structural instance creation expression is evaluated to a block, so
is a shorthand for
因此,它评估了块表达式(根据规范的第6.10条),具有上述限制。然而,为什么我不知道这种限制。抛出的错误可以在Type类中找到。 this location , which seems to confirm that this restriction is the cause of the error that you see. As you mentioned, encoding the function in a class removes the block expression restriction:
|
2
0
To me this sounds like a simplicity against generality case: there could be a new type variable generated every time a block is created capturing some type constructor instantiated with existential type, but that would make error diagnostics more difficult to understand. Also note that having a class turns the call into a fast INVOKEVIRTUAL, rather than invoking () method by reflection. |
Paul Spencer · 部分应用函数类型的函子 7 年前 |
cha · 将函数对象传递给std::function 7 年前 |
softshipper · fmap的参数太多 7 年前 |
Gaurav Sehgal · 函数指针与C中的函子++ 8 年前 |
Sam · std::bind创建的函子在哪里? 10 年前 |