gpt4 book ai didi

c++ - 在 C++ 标准中,下面的代码片段中不允许使用 `a = b + {1, 2}`?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:43:50 25 4
gpt4 key购买 nike

<分区>

在标准中,a = b + {1, 2} 下面的地方是不允许的?

class complex {
double re, im;
public:
complex(double r, double i) : re{ r }, im{ i } {}
complex& operator+=(const complex& other) { re += other.re; im += other.im; return *this; }
};

inline complex operator+(complex lhs, const complex& rhs)
{
lhs += rhs;
return lhs;
}

int main()
{
complex a{ 1, 1 };
complex b{ 2, -3 };
a += {1, 3}; // Ok
a = b + {1, 2}; // doesn't compile
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com