Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
class Foo { public: Foo& operator=(const Foo&) = default; private: const int i = 0; };
为什么=default允许在那里?它编译没有错误。我认为这=default应该失败,因为它不可能分配给const变量?
=default
const
究竟发生了什么?
当函数无法生成时(如情况),= default将其生成为= deleted 代替。如果您尝试使用该赋值运算符,您的编译器应该会产生错误。
= default
= delete