[英]"+=" operation not working between types std::complex<double> and __complex__ double
I'm using Eigen to perform some matrix manipulations in C++.我正在使用 Eigen 在 C++ 中执行一些矩阵操作。 In it, I have a line schematically of the form在其中,我有一条线的形式示意图
MatrixXcd A = MatrixXcd::Zeros(10,10);
A(0,0) += 2.0*1i;
Compiling this on my local computer gives no problems.在我的本地计算机上编译它没有问题。 However, compiling it on a different computer using the same CMake file gives the following error:但是,使用相同的 CMake 文件在不同的计算机上编译它会出现以下错误:
error: no match for 'operator+=' (operand types are 'Eigen::DenseCoeffsBase<Eigen::Matrix<std::complex<double>, -1, -1>, 1>::Scalar {aka std::complex<double>}' and '__complex__ double')
so somehow the types std::comple<double>
and __complex__ double
are different, and the computer is unable to resolve the difference.所以不知何故std::comple<double>
__complex__ double
std::comple<double>
和__complex__ double
类型不同,计算机无法解决差异。 Can someone explain to me what these differences are, and how to remove the discrepancy?有人可以向我解释这些差异是什么,以及如何消除差异? I could try figuring out how the two computers are configured differently, but that seems like a more difficult problem to get help with online.我可以尝试弄清楚两台计算机的配置方式有何不同,但这似乎是一个更难获得在线帮助的问题。
C++ 14 added new literal syntax to make a+bi
evaluate to a std::complex<double>
. C++ 14 添加了新的文字语法,使a+bi
计算为std::complex<double>
。
It should suffice to add应该足够了
set(CMAKE_CXX_STANDARD 14) # or 17
to your CMakeLists.txt file to make both compilers agree again.到你的 CMakeLists.txt 文件,让两个编译器再次一致。
Ensure you add the line确保添加行
using namespace std::complex_literals;
at beginning of your main() function.在 main() 函数的开头。
Also check that probably you want to do A(0,0) += 2.0 + 1i;
还要检查您是否想要执行A(0,0) += 2.0 + 1i;
instead of A(0,0) += 2.0*1i;
而不是A(0,0) += 2.0*1i;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.