Calling a Method in Constructor

前端 未结 5 1980
情书的邮戳
情书的邮戳 2020-12-28 15:49

Herb Sutter mentions in one of his http://www.gotw.ca articles that an object is constructed(has valid existence) only if the constructor executes completes.ie to put it in

5条回答
  •  臣服心动
    2020-12-28 16:14

    Beware of member variables that are not yet initialized. Beware of virtual functions: the function that you call might not be the one that you expect if the function is virtual and a derived object is created. Other than that, I do not see any problem calling methods from the constructor. Especially the memory for the object has already been allocated.

提交回复
热议问题