![](/img/trans.png)
[英]error: use of ‘auto’ in lambda parameter declaration only available with ‘-std=c++14’ or ‘-std=gnu++14’ and PCL errors
[英]error: use of 'auto' in lambda parameter declaration only available with -std=c++1y or -std=gnu++1y [-Werror]
我有一个模板函数,可以将其放入输出流中,而无需担心类型。 这是一个 C++ 14 兼容代码,它具有 auto 作为 lambda 的参数。 但是,我需要我的编译器设置为 C++ 11。我做了哪些更改来解决这个问题,以便它也适用于 C++ 11。
这是我的代码
template<class... Args >
std::string build_message( Args&&... args )
{
auto aPrintImplFn = [](auto& os, auto&& ... ts) {
// expression (void) just to suppress the unused variable warning
(void)std::initializer_list<char> { (os << ts, '0')... };
};
std::ostringstream out;
aPrintImplFn(out, std::forward<Args>(args)...);
return out.str();
}
将auto
改为显式类型,如下
#include <sstream>
#include <string>
#include <iostream>
template<class... Args >
std::string build_message( Args&&... args )
{
auto aPrintImplFn = [](std::ostringstream & os, Args&& ... ts) {
// expression (void) just to suppress the unused variable warning
(void)std::initializer_list<char> { (os << ts, '0')... };
};
std::ostringstream out;
aPrintImplFn(out, std::forward<Args>(args)...);
return out.str();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.