更新时间:2023-11-11 12:09:34
可以想到没有理由,它将被明确禁止。我猜这只是g ++的暂时限制。
I can think of no reason that it would be specifically disallowed. I'm guessing that it's just a temporary limitation of g++.
我也尝试了其他几个:
template <class T>
void foo(void (*f)(void)) {}
foo<int>([]{});
可以工作。
typedef void (*fun)(void);
template <class T>
fun foo() { return []{}; } // error: Cannot convert.
foo<int>()();
这不是(但如果 foo
未参数化)。
That doesn't (but does if foo
is not parameterized).
注意:我只在g ++ 4.5中测试。
Note: I only tested in g++ 4.5.