《More Effective C++》------ ( 1 )
《More Effective C++》------ ( 3 )

《More Effective C++》------ ( 2 )

Timothy posted @ 2010年6月08日 01:10 in Reading Notes , 1162 阅读

 条款6:区别increment / decrement操作符的前置和后置形式

(1):prefix和postfix语法上有区别,因为他们的函数形式表面上一样的,于是实际上 postfix 是多了一个参数的,值始终为0而已。


      int& operator++() .............                ++i;

      const int operator++( int ).............   i++(0);

(2):从效率上说,prefix比postfix高;从维护上说,一般的实现版本中,postfix代码调用prefix函数来完成累加动作,这样维护 加动作 只需要维护prefix的函数。


条款7:千万不要重载&&, ||和,操作符

(1): &&, || 有一定的提前判断,  ,操作符表示顺序执行,返回最后一个操作的值



.       .*          ::            ?:

new  delete sizeof  typeid



条款8:了解不同意义的new 和 delete

(1):new operator, 即new expression,    CA *p = new CA; 展开后为:  void *buffer = operator new ( size ),  在buffer上构建CA, 调用CA的构造函数

      这里的operator new 确实存在, #include <new> ( stl ), void* operator new( size_t  t );

(2):new 和 delete 对应, 分配内存并调用构造函数,  析构再删除内存。

      如果采用operator new 取得内存,在此内存上产生对象,则不要调用delete, 只需要调用析构,再free内存。 称为 placement new。


void *pBuffer = operator new( sizeof( CA ) );
if ( pBuffer != NULL )
    CA *pA = new( pBuffer ) CA();  //pA正常

    //delete pA;		//错误
    free( pBuffer );  



(3):数组, new[ ] 和 delete[ ] 要对应, 调用的constructor 和 destructor数量跟数组的元素个数相关。

(4):new operator和delete operator属于内建操作符,不可修改其行为;但是 operator new 和 operator delete 则可修改其行为。










(1):本条款的思想就是: 利用exception发生时,析构可以自动调用,避免内存泄露。



CA *pA = new pA;
delete pA;






CAObject obj( new CA );




Punjab Plus One Prev 说:
2022年8月24日 21:52

The Punjab Board Class 11th Important Model Question Paper 2023 would be helpful to those who desire to succeed in the Class 11 Punjab Board Exam. Due to a more precise indication of the assignments and tests they will be expected to complete during the academic year, students will be better equipped to handle the Punjab Board 11th Grade. <a href="https://www.modelpaper2020.in/punjab-1-model-paper-202/">Punjab Plus One Previous Paper 2023</a> It will be important for students to participate in its creation, and a well-designed Subjects Wise Important Model Question Paper 2023 will work to make it as interactive as possible by including students in the process of making it.

Grade 8 Result chitt 说:
2022年9月03日 22:58

Chittagong is also another best education board under all education board Bangladesh, and this is also one of the divisions under eight education boards of the country, the Secondary and Higher Secondary Education Board has successfully completed those Junior School Certificate and Junior Dakil (Grade-8) annual final examination tests between 2nd to 11th November 2022 with the same schedule of all education board. Grade 8 Result chittagong The School Education Department has announced there are lakhs of students are appeared and participated in the JSC & JDC terminal examinations 2022 from all districts of Chittagong division, the Grade 8th standard examinations are successfully completed and the students are waiting to get JSC Result 2022 with total marksheet with subject wise marks.

登录 *

loading captcha image...
or Ctrl+Enter