《Effective C++》: 编译器的复仇

来源:互联网 发布:python中类的使用 编辑:程序博客网 时间:2024/04/28 19:40

今天看到《Effective C++》Item12中一段比较有意思的描述:

当我们为类亲自构造copy constructor和assign operator函数时,编译器不会再自动生成copy constructor和assign operator。这时,假设我们为类新添加了成员变量,但是忘记在copy constructor和assign operator函数中做相应修改时(即partial copy),编译器也不会做任何警告,Scott Meyers对此进行的描述是:

“Yet most compilers say nothing about this, not even at maximal warning level (see alsoItem 53). That's their revenge for your writing the copying functions yourself. You reject the copying functions they'd write, so they don't tell you if your code is incomplete.”

哈哈哈,看到这些会心一笑,编译器好小气的说。Scott Meyers真有意思。

原创粉丝点击