码迷,mamicode.com
首页 > 其他好文 > 详细

12.18

时间:2018-12-24 12:32:39      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:sid   function   problem   art   list   initial   ram   with   func   

Effective C++ Scott Meyers  

Chapter 1. Uses and Abuses of vector

1. Item 4: Make sure that objects are initialized before they‘re used.

  Use member initialization list to initialize the member.

  Sometimes, the initialization list must be used, even for built-in types. For example, data members that are const or are references must be initialized.

  Always list members in the initialization list in the same order as they‘re declared in the class.

  When class has multiple constructors, omit the entries in the list for data members where assignment works as well as true initialization, moving the assignments to a single function that all the constructors call.

  Static objects declared inside functions are known as local static objects, and the other kinds of static objects are known as non-local static objects.

  The relative order of initialization of non-local static objects defined in different translation units is undefined.

  Define the non-local static objects in local functions, where it‘s declared static. These functions return references to the objects they contain. (Singleton Pattern)

  The functions contain static objects makes them problematic in multithreaded systems. One way to deal with it is to manually invoke all the reference-returning functions during the single-threaded startup portion of the program. This eliminates initialization-related race conditions.

12.18

标签:sid   function   problem   art   list   initial   ram   with   func   

原文地址:https://www.cnblogs.com/lefthook/p/10167913.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!