[英]c++ lambda capture not supported in firebase 5.4.4?
我正在从官方网站https://firebase.google.com/docs/auth/cpp/password-auth#register_callback_on_future关注c ++教程
在那边提到,不支持lambda捕获,因为那里的编译器不支持std :: function。 但是,在2017年8月23日发布的https://firebase.google.com/support/release-notes/cpp-relnotes版本4.1.0中,提到它们已经添加了对lambda捕获的支持。
当我写这样的函数
void CreateUserInFirebase(const std::string& Email, const std::string& Password)
{
auth->CreateUserWithEmailAndPassword(Email.c_str(), Password.c_str());
firebase::Future<firebase::auth::User*> Result = auth->CreateUserWithEmailAndPasswordLastResult();
Result.OnCompletion([&SomeVariable](const firebase::Future<firebase::auth::User*>& result, void* user_data)
{}, nullptr);
}
它给这个错误
错误:没有匹配的成员函数可调用“ OnCompletion”
注意:候选函数不可行:第一个参数没有从lambda到'firebase :: Future :: TypedCompletionCallback'(aka'void(*)(const Future&,void *)')的已知转换
是否已删除最新版本的支持?
谢谢。
OnCompletion
有两个重载:
OnCompletion(TypedCompletionCallback callback, void *user_data) const
和
OnCompletion(std::function< void(const Future< ResultType > &)> callback) const
您定义了带两个参数的lambda,因此编译器选择第一个重载,但是lambda捕获SomeVariable
代码无法编译,带有捕获的lambda无法转换为函数指针。
如果要调用第二个重载,则lambda应该只采用一个参数(可以在捕获列表中传递user_data
)。
Result.OnCompletion([&SomeVariable](const firebase::Future<firebase::auth::User*>& result) {});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.