Effective C++ 学习(1)

1.被声明为explicit的构造函数通常比其non-explicit兄弟更受欢迎,因为它们禁止编译器执行非预期的类型转换。除非有好的理由进行隐式转换,最好使用explicit。

2.尽量以const、enum、inline替换#define,可以使编译器看到并且记住。下为在类中声明常量

class GamePlayer
{
private:
 static const int Num = 5;
 int source[Num];
};

此为声明式,非定义式,要是需要定义为const int GamePlayer::Num ;不需要重新赋值,否则出错!

posted @ 2012-07-11 12:17  飞天0407  阅读(113)  评论(0编辑  收藏  举报