我目前正试图了解 noexcept (就像几乎所有我避免使用旧的“运行时异常规范”的人一样)。虽然我认为我了解了 noexcept 的基本概念,但我不确定在以下情况下会发生什么:
class sample {
public:
sample() noexcept { }//this doesn't throw
sample(const sample & s) noexcept { }
sample(sample && s) noexcept { }
sample & operator=(const sample & s) noexcept {...}
sample & operator=(sample && s) noexcept { ... }
~sample() noexcept() { }//this should never ever throw
sample operator-() const { return *this * -1; }//assuming that there is a operator*…
sample & operator*=(const sample & s) noexcept { ... }
};
sample operator*(sample s1, const sample & s2) { return s1 *= s2; }//same problem as with operator-…
将 sample::operator- 声明为 noexcept 是否安全?(考虑到它在返回时调用构造函数)
编辑:我更新了代码部分,因为问题的中心部分似乎不清楚......</p>