问题描述
我使用C ++中的< complex>
库。是否可以使用[]运算符访问复数的实部和复数部分?我想使用 myComplexNum [0]
而不是 myComplexNum.real()
和 myComplexNum [ 1]
而不是 myComplexNum.imag()
。
使用MingW 4.5.2,我收到错误:没有找到与operator []'
匹配。我真的需要使用[]运算符现在,因为否则我将不得不改变几百行代码。
没有。
您可以从 std :: complex<>
并继承构造函数并添加一个重写的 operator []
,但我建议反对。 >
I'm using the <complex>
library in C++. Is it possible to access the real and complex parts of a complex number using the [] operator? I want to use myComplexNum[0]
instead of myComplexNum.real()
and myComplexNum[1]
instead of myComplexNum.imag()
.
I tried to do it using MingW 4.5.2, and I receive the error: no match found for 'operator[]'
. I really need to use the [] operator for now, because otherwise I would have to change hundreds of lines of code.
Nope.
You could derive from std::complex<>
and inherit constructors and add an overridden operator[]
, but I would advise against it.
这篇关于是否可以使用C ++中的[]运算符访问复数的实部和虚部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!