Boost FFT 示例 - 编译错误,这段代码在做什么?
Boost FFT Example - error on compile, what is this code doing?
我正在按照以下示例进行操作 link:
我在以下行收到错误:
[&n](cpp_dec_float_50& y)
g++ -I ../boost_1_71_0 fft.cpp -o fft
fft.cpp:52:3: error: expected expression
[&n](cpp_dec_float_50& y)
^
1 error generated.
完整块是:
// Generate the sine values.
std::for_each
(
sin_values.begin (),
sin_values.end (),
[&n](cpp_dec_float_50& y)
{
y = sin( pi<cpp_dec_float_50>() / pow(cpp_dec_float_50 (2), n));
++n;
}
);
“[&n](cpp_dec_float_50& y)”到底在做什么?为什么会出错?
What is [&n](cpp_dec_float_50& y)
actually doing?
它是 lambda expression 的第一部分,即 一个匿名函数。
And why is it erroring?
您需要针对 C++11(或更高版本)进行编译。在编译器命令行中使用 -std=c++11
(或 -std=c++14
或 -std=c++17
)。 例如:
g++ -std=c++11 ...
我正在按照以下示例进行操作 link:
我在以下行收到错误:
[&n](cpp_dec_float_50& y)
g++ -I ../boost_1_71_0 fft.cpp -o fft
fft.cpp:52:3: error: expected expression
[&n](cpp_dec_float_50& y)
^
1 error generated.
完整块是:
// Generate the sine values.
std::for_each
(
sin_values.begin (),
sin_values.end (),
[&n](cpp_dec_float_50& y)
{
y = sin( pi<cpp_dec_float_50>() / pow(cpp_dec_float_50 (2), n));
++n;
}
);
“[&n](cpp_dec_float_50& y)”到底在做什么?为什么会出错?
What is
[&n](cpp_dec_float_50& y)
actually doing?
它是 lambda expression 的第一部分,即 一个匿名函数。
And why is it erroring?
您需要针对 C++11(或更高版本)进行编译。在编译器命令行中使用 -std=c++11
(或 -std=c++14
或 -std=c++17
)。 例如:
g++ -std=c++11 ...