【问题标题】:Complex functions that worked in gcc4x do not work in gcc8x在 gcc4x 中工作的复杂函数在 gcc8x 中不起作用
【发布时间】:2020-12-17 01:28:19
【问题描述】:

我正在尝试使用 gcc 8.2.1 在 RHEL8 中构建以下内容。这以前使用 gcc 4.8.5 与 RHEL7 一起工作。

#include <vector> 
#include <algorithm>
#include <complex>
vector<complex<float> > x, y;

transform(x.begin(), x.end(), y.begin(), conj<float>);

我得到一个错误 no matching function for call to the above line and points to close ')' 如果我尝试使用其他复杂函数代替conj,即argnorm,则会出现同样的错误。 其他使用转换的complex&lt;float&gt; 操作确实有效,例如 transform(x.begin(), x.end(), y.begin(), bind2nd(minus&lt;complex&lt;float&gt; &gt;(), someComplexFloat)); 其中someComplexFloat 的类型为complex&lt;float&gt; someComplexFloat;

有什么建议吗?

【问题讨论】:

    标签: c++ algorithm vector complex-numbers


    【解决方案1】:

    std::conj 自 C++11 以来有几个(模板)重载,所以它是模棱两可的。

    通过重载集的方法是使用 lambda

    std::transform(x.begin(), x.end(), y.begin(), [](auto c){ return std::conj(c); });
    

    Demo.

    【讨论】:

    • 正如所写,上述建议无法编译。即使在 conj(c) 之后添加了一个结束 '}'; }); .我收到一个错误:错误:'c' 没有命名类型还有其他建议吗?
    • @David:修正了错字,添加了演示。如果您在 C++11 中,则没有通用 lambda,您应该将 auto 替换为 std::complex&lt;float&gt;
    猜你喜欢
    • 1970-01-01
    • 2023-03-29
    • 2014-01-12
    • 1970-01-01
    • 2020-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-16
    相关资源
    最近更新 更多