赋值与初始化

1、赋值与初始化之间的根本区别:

  赋值总是消除一个原始值,而初始化从来不会。相反,初始化牵扯到创建一个新的对象并同时给其一个值。

2、初始化发生在:

  • In variable declarations(变量定义)
  • For function parameters on entry to a function(函数参数)
  • For the return value of a function on return from the function(函数返回值)
  • In constructor initializers(初始化列表)

3、赋值仅发生在表达式中有“=”操作符时。

4、初始化和赋值引起不同的操作:  

    • Constructors always control initialization.(初始化---->构造函数)
    • The operator= member function always controls assignment.(赋值---->赋值操作符)

参考:《Accelerated C++》by Andrew Koenig and Barbara E. Moo

posted @ 2011-05-17 19:48  iThinking  阅读(259)  评论(0编辑  收藏  举报