我在使用Clang编译以下代码时遇到问题:
#include <functional>
struct C {
void m() const {}
};
int main() {
C c;
std::function<void(C*)> f1 = &C::m;
f1(&c);
std::function<void(C&)> f2 = &C::m;
f2(c);
std::function<void(C)> f3 = &C::m;
f3(c);
}
报告的错误很长,可以看到here。
GCC能够编译它。
如果删除了const
限定符,则代码将在GCC和Clang上成功编译。
我使用的版本是:GCC 4.8.4,Clang 3.6.0。