随笔分类 -  Effective C++

摘要:class TimeKeeper{public: TimeKeeper() ; ~TimeKepper() ; ...} ;class AtomicClock:public TimeKeeper{...}// 原子钟class WaterClock:public TimeKeeper{...}// 水钟class WristWatch:public TimeKeeper{...}// 腕表根据工厂模式,会返回一个base class指针指向新生成的derived class对象。TimeKeeper* getTimeKeeper() ;// 返回一个指针,指向一个TimeKe... 阅读全文
posted @ 2013-07-12 20:52 2011winseu 阅读(557) 评论(0) 推荐(0)
摘要:1. 当只写一个空类的时候,编译器会为他声明一个copy构造函数,一个copy assignment函数和一个析构函数。如下:如果写下:class Empty{ };编译器就会实现以下代码:class Empty{ Empty(){} //默认构造函数 Empty(const Empty& rhs ) {} //复制构造函数 ~Empty() {} //析构函数 Empty& operator=( const Empty& rhs ) {} // 复制赋值操作符};编译器产生的是non-virtual函数。默认产生以上四种构造函数。如果要使这些编译器默... 阅读全文
posted @ 2013-07-11 19:40 2011winseu 阅读(420) 评论(1) 推荐(0)
摘要:对于内置类型以外的初始化责任落在构造函数身上。如下:class PhoneNumber{};class ABEntry{public: ABEntry( const string& name, const string& address, const list& phones );private: string theName; string theAddress; list thePhones; int numTimesConsulted;};ABEntry::ABEntry( const string& name, const string& add 阅读全文
posted @ 2013-07-10 11:46 2011winseu 阅读(692) 评论(0) 推荐(0)
摘要:char greeting[] = "hello";char* p = greeting; //non-const pointer,non-const dataconst char* p = greeting; //non-const pointer, const datachar* const p = greeting; //const pointer,non-const dataconst char* const p = greeting; //const pointer, const ... 阅读全文
posted @ 2013-07-09 17:40 2011winseu 阅读(237) 评论(0) 推荐(0)