摘要: 假设程序涉及矩形。为了让Rectangle对象尽可能小,可能把定义矩形的点放在一个辅助的struct内再让Rectangle去指它: class Point{ public: Point(int x, int y); ... void setX(int newVal); void setY(int newVal... 阅读全文
posted @ 2012-02-02 16:22 lidan 阅读(460) 评论(0) 推荐(0)
摘要: 转型(casts)破坏了类型系统(type system)。可能导致任何类型的麻烦。c++提供四种新式转型const_cast<T>(expression) //cast away the constnessdynamic_cast<T>(expression) //safe downcasting安全向下转型reinterpret_cast<T>(expression)//意图执行低级转型,实际动作(及结果)可能取决于编译器,这也表示它不可移植;低级代码以外很少见static_cast<T>(expression)//用来强迫隐式转换(impl 阅读全文
posted @ 2012-02-02 14:13 lidan 阅读(461) 评论(0) 推荐(0)