亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ei47.htm

?? 教你如何編寫有效簡潔的出C++程序
?? HTM
字號:
 Effective C++, 2E | Item 47: Ensure that non-local static objects are initialized before they're used Back to Item 46: Prefer compile-time and link-time errors to runtime errors.Continue to Item 48: Pay attention to compiler warnings.Item 47: Ensure that non-local static objects are initialized before they're used.You're an adult now, so you don't need me to tell you it's foolhardy to use an object before it's been initialized. In fact, the whole notion may strike you as absurd; constructors make sure objects are initialized when they're created, n'est-ce pas?Well, yes and no. Within a particular translation unit (i.e., source file), everything works fine, but things get trickier when the initialization of an object in one translation unit depends on the value of another object in a different translation unit and that second object itself requires initialization.For example, suppose you've authored a library offering an abstraction of a file system, possibly including such capabilities as making files on the Internet look like they're local. Since your library makes the world look like a single file system, you might create a special object, theFileSystem, within your library's namespace (see Item 28) for clients to use whenever they need to interact with the file system abstraction your library provides: class FileSystem { ... };            // this class is in your                                     // libraryFileSystem theFileSystem;            // this is the object                                     // with which library                                     // clients interactBecause theFileSystem represents something complicated, it's no surprise that its construction is both nontrivial and essential; use of theFileSystem before it had been constructed would yield very undefined behavior. (However, consult Item M17 for ideas on how the effective initialization of objects like theFileSystem can safely be delayed.)Now suppose some client of your library creates a class for directories in a file system. Naturally, their class uses theFileSystem: class Directory {                    // created by library clientpublic:  Directory();  ...};Directory::Directory(){  create a Directory object by invoking member  functions on theFileSystem;}Further suppose this client decides to create a distinguished global Directory object for temporary files: Directory tempDir;                  // directory for temporary                                    // filesNow the problem of initialization order becomes apparent: unless theFileSystem is initialized before tempDir, tempDir's constructor will attempt to use theFileSystem before it's been initialized. But theFileSystem and tempDir were created by different people at different times in different files. How can you be sure that theFileSystem will be created before tempDir?This kind of question arises anytime you have non-local static objects that are defined in different translation units and whose correct behavior is dependent on their being initialized in a particular order. Non-local static objects are objects that are defined at global or namespace scope (e.g., theFileSystem and tempDir), declared static in a class, or defined static at file scope.Regrettably, there is no shorthand term for "non-local static objects," so you should accustom yourself to this somewhat awkward phrase.You do not want the behavior of your software to be dependent on the initialization order of non-local static objects in different translation units, because you have no control over that order. Let me repeat that. You have absolutely no control over the order in which non-local static objects in different translation units are initialized.It is reasonable to wonder why this is the case.It is the case because determining the "proper" order in which to initialize non-local static objects is hard. Very hard. Halting-Problem hard. In its most general form with multiple translation units and non-local static objects generated through implicit template instantiations (which may themselves arise via implicit template instantiations) it's not only impossible to determine the right order of initialization, it's typically not even worth looking for special cases where it is possible to determine the right order.In the field of Chaos Theory, there is a principle known as the "Butterfly Effect." This principle asserts that the tiny atmospheric disturbance caused by the beating of a butterfly's wings in one part of the world can lead to profound changes in weather patterns in places far distant. Somewhat more rigorously, it asserts that for some types of systems, minute perturbations in inputs can lead to radical changes in outputs.The development of software systems can exhibit a Butterfly Effect of its own. Some systems are highly sensitive to the particulars of their requirements, and small changes in requirements can significantly affect the ease with which a system can be implemented. For example, Item 29 describes how changing the specification for an implicit conversion from String-to-char* to String-to-const-char* makes it possible to replace a slow or error-prone function with a fast, safe one.The problem of ensuring that non-local static objects are initialized before use is similarly sensitive to the details of what you want to achieve. If, instead of demanding access to non-local static objects, you're willing to settle for access to objects that act like non-local static objects (except for the initialization headaches), the hard problem vanishes. In its stead is left a problem so easy to solve, it's hardly worth calling a problem any longer.The technique sometimes known as the Singleton pattern is simplicity itself. First, you move each non-local static object into its own function, where you declare it static. Next, you have the function return a reference to the object it contains. Clients call the function instead of referring to the object. In other words, you replace non-local static objects with objects that are static inside functions. (See also Item M26.)The basis of this approach is the observation that although C++ says next to nothing about when a non-local static object is initialized, it specifies quite precisely when a static object inside a function (i.e. a local static object) is initialized: it's when the object's definition is first encountered during a call to that function. So if you replace direct accesses to non-local static objects with calls to functions that return references to local static objects inside them, you're guaranteed that the references you get back from the functions will refer to initialized objects. As a bonus, if you never call a function emulating a non-local static object, you never incur the cost of constructing and destructing the object, something that can't be said for true non-local static objects.Here's the technique applied to both theFileSystem and tempDir: class FileSystem { ... };            // same as beforeFileSystem& theFileSystem()          // this function replaces{                                    // the theFileSystem object  static FileSystem tfs;             // define and initialize                                     // a local static object                                     // (tfs = "the file system")  return tfs;                        // return a reference to it}class Directory { ... };             // same as beforeDirectory::Directory(){  same as before, except references to theFileSystem are  replaced by references to theFileSystem();}Directory& tempDir()                 // this function replaces{                                    // the tempDir object  static Directory td;               // define/initialize local                                     // static object  return td;                         // return reference to it}Clients of this modified system program exactly as they used to, except they now refer to theFileSystem() and tempDir() instead of theFileSystem and tempDir. That is, they refer only to functions returning references to those objects, never to the objects themselves.The reference-returning functions dictated by this scheme are always simple: define and initialize a local static object on line 1, return it on line 2. That's it. Because they're so simple, you may be tempted to declare them inline. Item 33 explains that late-breaking revisions to the C++ language specification make this a perfectly valid implementation strategy, but it also explains why you'll want to confirm your compilers' conformance with this aspect of the standard before putting it to use. If you try it with a compiler not yet in accord with the relevant parts of the standard, you risk getting multiple copies of both the access function and the static object defined within it. That's enough to make a grown programmer cry.Now, there's no magic going on here. For this technique to be effective, it must be possible to come up with a reasonable initialization order for your objects. If you set things up such that object A must be initialized before object B, and you also make A's initialization dependent on B's having already been initialized, you are going to get in trouble, and frankly, you deserve it. If you steer shy of such pathological situations, however, the scheme described in this Item should serve you quite nicely. Back to Item 46: Prefer compile-time and link-time errors to runtime errors.Continue to Item 48: Pay attention to compiler warnings. 

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品国产三级国产普通话99| 欧美日韩五月天| 久久在线免费观看| 久久99国产乱子伦精品免费| 久久这里都是精品| 成人av先锋影音| 亚洲免费av高清| 欧美中文字幕一二三区视频| 一区二区三区免费| 欧美日韩大陆在线| 久久99精品一区二区三区| 精品国产一二三区| 波波电影院一区二区三区| 一区二区三区四区五区视频在线观看| 欧美日韩专区在线| 麻豆成人久久精品二区三区红| 久久久久久久久久美女| 成人精品在线视频观看| 亚洲一区视频在线| 精品成人一区二区三区| 白白色亚洲国产精品| 亚洲影视在线播放| 久久日一线二线三线suv| 成人午夜大片免费观看| 亚洲国产日日夜夜| 久久久久久久综合| 精品视频一区 二区 三区| 久久99久久精品| 亚洲精选免费视频| 欧美成人伊人久久综合网| 成人福利视频网站| 日韩av电影免费观看高清完整版 | 老司机午夜精品| 国产欧美日韩在线| 欧美日本高清视频在线观看| 国产成人日日夜夜| 天天色 色综合| 国产女同性恋一区二区| 欧美高清视频不卡网| 成人免费观看视频| 久久精品国产澳门| 亚洲制服丝袜在线| 国产精品视频麻豆| 日韩欧美在线影院| 91久久精品一区二区三区| 国产精品亚洲专一区二区三区| 亚洲成av人片www| 1000部国产精品成人观看| 欧美一区二区久久| 欧美亚洲图片小说| gogo大胆日本视频一区| 老色鬼精品视频在线观看播放| 亚洲精品国产高清久久伦理二区| 337p粉嫩大胆噜噜噜噜噜91av | 成人手机在线视频| 久久99久久99| 日韩精品亚洲一区二区三区免费| 亚洲精品午夜久久久| 欧美经典一区二区三区| 欧美成人官网二区| 日韩一级免费观看| 91麻豆精品国产91久久久使用方法| 91在线视频播放地址| 懂色av一区二区在线播放| 国产永久精品大片wwwapp| 日韩成人免费电影| 丝袜美腿亚洲色图| 日韩经典一区二区| 日日夜夜精品免费视频| 亚洲bt欧美bt精品| 偷拍一区二区三区四区| 亚洲国产精品天堂| 在线播放日韩导航| 奇米影视7777精品一区二区| 亚洲一区二区三区国产| 亚洲一区在线观看免费观看电影高清 | 国产suv精品一区二区6| 亚洲777理论| 另类专区欧美蜜桃臀第一页| 成人天堂资源www在线| 国产精品中文字幕日韩精品| 加勒比av一区二区| 国产一区二区三区电影在线观看| 久久99日本精品| 蜜乳av一区二区| 国产一区视频导航| 国产麻豆精品95视频| 国产成人精品1024| www.av精品| 日本精品免费观看高清观看| 欧美午夜电影在线播放| 欧美精品 国产精品| 日韩一区二区三区电影在线观看| 日韩欧美国产小视频| 欧美不卡一二三| 国产婷婷一区二区| 亚洲视频在线一区| 亚洲成人精品影院| 另类综合日韩欧美亚洲| 国产精品一区二区三区四区| 成人国产精品视频| 欧美日韩一卡二卡三卡| 91精品国产综合久久精品app| 日韩欧美色综合| 国产精品三级av在线播放| 亚洲精品日韩综合观看成人91| 樱桃国产成人精品视频| 青青草国产成人99久久| 极品瑜伽女神91| 91美女精品福利| 正在播放亚洲一区| 欧美国产精品中文字幕| 亚洲精品伦理在线| 久久91精品久久久久久秒播| 亚洲成人777| 综合久久久久综合| 日本伊人色综合网| 国产成人综合在线播放| 色综合天天视频在线观看| 制服丝袜在线91| 欧美国产日韩精品免费观看| 亚洲精品中文在线观看| 韩国毛片一区二区三区| 日本高清不卡在线观看| 久久日一线二线三线suv| 亚洲美女视频在线观看| 国产一区二区三区视频在线播放| 欧美综合视频在线观看| ww久久中文字幕| 午夜不卡av免费| 99久久伊人久久99| 欧美精品一区二区高清在线观看| 亚洲你懂的在线视频| 国产露脸91国语对白| 欧美精品高清视频| 最新国产精品久久精品| 久久99精品国产麻豆婷婷洗澡| 欧美伊人久久久久久午夜久久久久| 久久久久国产精品人| 香蕉久久一区二区不卡无毒影院| youjizz国产精品| 久久奇米777| 青椒成人免费视频| 欧美久久一区二区| 亚洲欧美一区二区三区国产精品| 国产精品资源在线观看| 91麻豆精品国产91久久久资源速度| 亚洲欧美日韩中文播放| 精品一区二区三区在线播放 | 国产精品亚洲一区二区三区妖精| 8x8x8国产精品| 亚洲国产日韩a在线播放性色| 成人免费视频免费观看| 国产成人精品影视| 欧美日韩在线观看一区二区| 国产精品久久久一本精品| 国产精品一卡二卡| 久久中文字幕电影| 国产在线精品国自产拍免费| 日韩一区二区三区免费看| 婷婷国产在线综合| 欧美日本一区二区| 视频一区视频二区中文| 欧美日韩国产123区| 香蕉乱码成人久久天堂爱免费| 欧美亚洲一区二区三区四区| 一区二区三区久久久| 91福利国产精品| 亚洲国产一区视频| 欧美日韩二区三区| 男女性色大片免费观看一区二区 | 波多野洁衣一区| 国产精品免费久久久久| 成人免费的视频| 国产精品久久久久久久久免费桃花| 国产福利一区二区三区| 亚洲国产精品成人综合色在线婷婷| 成人性生交大片免费| 中文字幕在线播放不卡一区| 97超碰欧美中文字幕| 亚洲精品videosex极品| 欧美日韩国产天堂| 蜜桃av一区二区| 国产女主播一区| av动漫一区二区| 亚洲动漫第一页| 91精品国产手机| 国产一区欧美一区| 国产精品污网站| 日本高清不卡在线观看| 欧美一级二级三级蜜桃| 亚洲va韩国va欧美va精品| 欧美一区午夜视频在线观看| 另类欧美日韩国产在线| 亚洲国产精品ⅴa在线观看| 一本大道久久a久久综合 | 五月天亚洲婷婷| 久久久三级国产网站| 91视频一区二区三区| 日韩高清不卡一区二区|