std::complex<T>::complex
来自 cppreference.cn
| 主要模板 (std::complex<T>) |
||
| (1) | ||
| complex( const T& re = T(), const T& im = T() ); |
(直至 C++14) | |
| constexpr complex( const T& re = T(), const T& im = T() ); |
(C++14 起) | |
| (2) | ||
| complex( const complex& other ); |
(直至 C++14) | |
| constexpr complex( const complex& other ); |
(C++14 起) (直至 C++23) |
|
| constexpr complex( const complex& other ) = default; |
(C++23 起) | |
| (3) | ||
| template< class X > complex( const complex<X>& other ); |
(直至 C++14) | |
| template< class X > constexpr complex( const complex<X>& other ); |
(C++14 起) (直至 C++23) |
|
| template< class X > constexpr explicit(/* 参见下方 */) complex( const complex<X>& other ); |
(C++23 起) | |
| 标准显式特化 std::complex<float> (直至 C++23) |
||
| (1) | ||
| complex( float re = 0.0f, float im = 0.0f ); |
(C++11 前) | |
| constexpr complex( float re = 0.0f, float im = 0.0f ); |
(C++11 起) | |
| constexpr complex( const complex<float>& other ) = default; |
(2) | (C++20 起) |
| (3) | ||
| explicit complex( const complex<double>& other ); explicit complex( const complex<long double>& other ); |
(C++11 前) | |
| constexpr explicit complex( const complex<double>& other ); constexpr explicit complex( const complex<long double>& other ); |
(C++11 起) | |
| 标准显式特化 std::complex<double> (直至 C++23) |
||
| (1) | ||
| complex( double re = 0.0, double im = 0.0 ); |
(C++11 前) | |
| constexpr complex( double re = 0.0, double im = 0.0 ); |
(C++11 起) | |
| constexpr complex( const complex<double>& other ) = default; |
(2) | (C++20 起) |
| (3) | ||
| complex( const complex<float>& other ); explicit complex( const complex<long double>& other ); |
(C++11 前) | |
| constexpr complex( const complex<float>& other ); constexpr explicit complex( const complex<long double>& other ); |
(C++11 起) | |
| 标准显式特化 std::complex<long double> (直至 C++23) |
||
| (1) | ||
| complex( long double re = 0.0L, long double im = 0.0L ); |
(C++11 前) | |
| constexpr complex( long double re = 0.0L, long double im = 0.0L ); |
(C++11 起) | |
| constexpr complex( const complex<long double>& other ) = default; |
(2) | (C++20 起) |
| (3) | ||
| complex( const complex<float>& other ); complex( const complex<double>& other ); |
(C++11 前) | |
| constexpr complex( const complex<float>& other ); constexpr complex( const complex<double>& other ); |
(C++11 起) | |
构造 std::complex 对象。标准显式特化(std::complex<float>、std::complex<double> 和 std::complex<long double>)的构造函数声明与主模板不同。(直至 C++23)
1) 从实部 re 和虚部 im 构造复数。
2) 拷贝构造函数。用 other 的内容拷贝构造对象。拷贝构造函数在标准显式特化中隐式声明。(直至 C++20)
3) 转换构造函数。从不同类型的复数构造对象。
|
主模板提供一个转换构造函数模板,而每个标准显式特化为另外两个标准显式特化提供两个非模板构造函数。 当且仅当实部和虚部的转换不是窄化转换时,非模板构造函数是转换构造函数(即非显式)。 |
(直至 C++23) |
|
对于主模板,当且仅当 `T` 的浮点转换等级大于或等于 `X` 的浮点转换等级时,explicit 中的表达式才求值为 false。 |
(C++23 起) |
[编辑] 参数
| re | - | 实部 |
| im | - | 虚部 |
| 其他 | - | 另一个用作源的复数 |
[编辑] 注意
自 C++23 起,拷贝构造函数必须是平凡的,以满足可平凡拷贝 (TriviallyCopyable) 要求,但实现通常在所有模式下都使其平凡。
[编辑] 参阅
| 赋值内容 (public member function) | |
| 表示纯虚数的 std::complex 字面量 (function) | |
| C 文档 为 CMPLX
| |