Jer*_*ner 9 c++ c++17 nodiscard c++-attributes
假设我有这门课:
class [[nodiscard]] MyClass
{
public:
MyClass() : _x(x) {}
MyClass(int x) : _x(x) {}
private:
int _x;
};
Run Code Online (Sandbox Code Playgroud)
将标签单独添加[[nodiscard]]到类的构造函数中会改变什么吗?或者这对于[[nodiscard]]应用于类声明本身的标签来说是完全多余的,因此只会给头文件添加不必要的噪音?
(我的测试表明后者,但我可能会错过一些细微差别)