c – gcc无法使用此捕获编译通用lambda
发布时间:2020-12-16 03:00:38 所属栏目:百科 来源:网络整理
导读:参见英文答案 Calling `this` member function from generic lambda – clang vs gcc1 我无法使用gcc 6.1编译以下程序: #include iostream#include string#include vector#include iterator#include algorithmclass Foo{public: void apply() const { std::
参见英文答案 >
Calling `this` member function from generic lambda – clang vs gcc1
我无法使用gcc 6.1编译以下程序: #include <iostream> #include <string> #include <vector> #include <iterator> #include <algorithm> class Foo { public: void apply() const { std::for_each(std::cbegin(bars_),std::cend(bars_),[this] (const auto& x) { print(x); }); } private: std::vector<std::string> bars_; void print(const std::string& x) const { std::cout << x << ' '; } }; int main() { Foo foo {}; foo.apply(); return 0; } 错误信息是: error: cannot call member function 'void Foo::print(const string&) const' without object std::for_each(std::cbegin(bars_),[this] (const auto& x) { print(x); }); ^~~~~ >更改const auto& x到const std :: string& x使程序编译. 这是编译器的错误吗? 解决方法
这是一份记录在案的
gcc bug,截至2016年8月尚未解决.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |