摘要: 缺省情况下swap动作可由标准程序库提供的swap算法完成: namespace std{ template<typename T> void swap(T& a, T& b) { T temp(a); a = b; b = temp; } ... 阅读全文
posted @ 2012-01-20 23:47 lidan 阅读(1193) 评论(0) 推荐(0) 编辑
摘要: 令class支持类型隐式转换通常是个糟糕的主意。当然这条规定在建立数值类型时,有例外。假设一个class用来表现有理数,允许整数 “隐式转换为”有理数似乎很合理。 class Rational{ public: Rational(int numerator = 0, int denominator = 1); //刻意不为explicit;允许int-to-... 阅读全文
posted @ 2012-01-20 10:36 lidan 阅读(526) 评论(0) 推荐(0) 编辑