operators
运算符+,-,%2A,/%28 std::复合%29
template< class T > complex | (1) | |
---|---|---|
template< class T > complex<T> operator+( const complex<T>& lhs, const T& rhs | (2) | |
template< class T > complex<T> operator+( const T& lhs, const complex<T>& rhs | (3) | |
template< class T > complex<T> operator-( const complex<T>& lhs, const complex<T>& rhs | (4) | |
template< class T > complex<T> operator-( const complex<T>& lhs, const T& rhs | (5) | |
template< class T > complex<T> operator-( const T& lhs, const complex<T>& rhs | (6) | |
template< class T > complex<T> operator*( const complex<T>& lhs, const complex<T>& rhs | (7) | |
template< class T > complex<T> operator*( const complex<T>& lhs, const T& rhs | (8) | |
template< class T > complex<T> operator*( const T& lhs, const complex<T>& rhs | (9) | |
template< class T > complex<T> operator/( const complex<T>& lhs, const complex<T>& rhs | (10) | |
template< class T > complex<T> operator/( const complex<T>& lhs, const T& rhs | (11) | |
template< class T > complex<T> operator/( const T& lhs, const complex<T>& rhs | (12) | |
实现了复算法和混合复/标量算法的二进制算子。标量参数被视为复数,实数等于实数,虚部设为零。
1-3%29返回其参数的和。
4-6%29返回减法结果。rhs
从lhs
7-9%29乘以它的论点
10-12%分29lhs
通过rhs
参数
lhs, rhs | - | the arguments: either both complex numbers or one complex and one scalar of matching type (float, double, long double) |
---|
返回值
1-3%29complex<T>(lhs) += rhs
4-6%29complex<T>(lhs) -= rhs
7-9%29complex<T>(lhs) *= rhs
10-12%29complex<T>(lhs) /= rhs
注记
因为模板参数推导不考虑隐式转换,这些运算符不能用于混合整数/复杂算法。在所有情况下,标量必须具有与复数的基础类型相同的类型。
例
二次
#include <iostream>
#include <complex>
int main()
{
std::complex<double> c2(2, 0
std::complex<double> ci(0, 1
std::cout << ci << " + " << c2 << " = " << ci+c2 << '\n'
<< ci << " * " << ci << " = " << ci*ci << '\n'
<< ci << " + " << c2 << " / " << ci << " = " << ci+c2/ci << '\n'
<< 1 << " / " << ci << " = " << 1./ci << '\n';
// std::cout << 1.f/ci; // compile error
// std::cout << 1/ci; // compile error
}
二次
产出:
二次
(0,1) + (2,0) = (2,1)
(0,1) * (0,1) = (-1,0)
(0,1) + (2,0) / (0,1) = (0,-1)
1 / (0,1) = (0,-1)
二次
另见
operator+=operator-=operator/=operator*= | compound assignment of two complex numbers or a complex and a scalar (public member function) |
---|---|
operator+operator- | applies unary operators to complex numbers (function template) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。