是否可以使用C ++中的[]运算符访问复数的实部和虚部

编程入门 行业动态 更新时间:2024-10-09 17:19:34
本文介绍了是否可以使用C ++中的[]运算符访问复数的实部和虚部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用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 ++中的[]运算符访问复数的实部和虚部

本文发布于:2023-11-09 04:02:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571348.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:复数   可以使用   运算符

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!