锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲成人一级电影,情人伊人久久综合亚洲,亚洲电影在线播放http://m.tkk7.com/wenhl5656/category/45754.html鎯寵搗鍜岃佽倴鐮旂┒涓柇鐨勬棩瀛愶紝鍊嶈娓╅Θzh-cnMon, 09 Aug 2010 03:56:44 GMTMon, 09 Aug 2010 03:56:44 GMT60pImpl Idiomhttp://m.tkk7.com/wenhl5656/archive/2010/08/07/328217.html鐖卞悆楸煎ご鐖卞悆楸煎ごSat, 07 Aug 2010 14:58:00 GMThttp://m.tkk7.com/wenhl5656/archive/2010/08/07/328217.htmlhttp://m.tkk7.com/wenhl5656/comments/328217.htmlhttp://m.tkk7.com/wenhl5656/archive/2010/08/07/328217.html#Feedback0http://m.tkk7.com/wenhl5656/comments/commentRss/328217.htmlhttp://m.tkk7.com/wenhl5656/services/trackbacks/328217.html闄嶄綆鏂囦歡闂寸殑緙栬瘧渚濊禆鍏崇郴錛岄氳繃鎶婁竴涓狢lass鍒嗘垚涓や釜Class錛屼竴涓彧鎻愪緵鎺ュ彛錛屽彟涓涓礋璐e疄鐜拌鎺ュ彛錛屽疄鐜版帴鍙d笌瀹炵幇鐨勫垎紱匯傝繖涓垎紱葷殑鍏抽敭鍦ㄤ簬鈥滀互澹版槑鐨勪緷璧栨р濇浛鎹⑩滃畾涔夌殑渚濊禆鎬р濓紝鑰岀紪璇戜緷璧栨ф渶灝忓寲鐨勬湰璐ㄦ槸:璁╁ご鏂囦歡灝藉彲鑳界殑鑷垜婊¤凍錛屼竾涓鍋氫笉鍒幫紝鍒欒瀹冧笌鍏朵粬鏂囦歡鍐呯殑澹版槑寮忥紙鑰岄潪瀹氫箟寮忥級鐩鎬緷銆?br />
寮曠敤榪欓噷鐨勪竴浜涙弿榪幫細
The Pimpl idiom, also known as the compilation firewall or Cheshire Cat technique, is a "private implementation" technique useful only in CeePlusPlus and statically compiled languages like it...

Benefits:
  1. Changing private member variables of a class does not require recompiling classes that depend on it, thus make times are faster, and the FragileBinaryInterfaceProblem is reduced.
  2. The header file does not need to #include classes that are used 'by value' in private member variables, thus compile times are faster.
  3. This is sorta like the way SmallTalk automatically handles classes... more pure encapsulation.
Drawbacks:
  1. More work for the implementor.
  2. Doesn't work for 'protected' members where access by subclasses is required.
  3. Somewhat harder to read code, since some information is no longer in the header file.
  4. Run-time performance is slightly compromised due to the pointer indirection, especially if function calls are virtual (branch prediction for indirect branches is generally poor).
How to do it:
  1. Put all the private member variables into a struct.
  2. Put the struct definition in the .cpp file.
  3. In the header file, put only the ForwardDeclaration of the struct.
  4. In the class definition, declare a (smart) pointer to the struct as the only private member variable.
  5. The constructors for the class need to create the struct.
  6. The destructor of the class needs to destroy the struct (possibly implicitly due to use of a smart pointer).
  7. The assignment operator and CopyConstructor need to copy the struct appropriately or else be disabled.
Code錛?/font>
1聽聽struct聽AImp;
2聽聽class聽A聽{
3聽聽public:
4聽聽聽聽//聽Same聽public聽interface聽as聽A,聽but聽all聽delegated聽to聽concrete聽implementation.
5聽聽private:
6聽聽聽聽AImp聽*聽pimpl;
7聽聽};
8


If you use a SmartPointer and you only have one implementation, there is no need to make any of the member functions virtual, except possibly the destructor. The run-time cost of non-virtual member function calls is much lower, and a compiler that does whole-program optimization can inline them even though they're in a separate translation unit. Here's an example:
聽1//聽foo.h
聽2
聽3聽聽class聽foo_impl;
聽4
聽5聽聽class聽foo聽{
聽6聽聽聽聽//聽Boilerplate
聽7聽聽聽聽friend聽class聽foo_impl;
聽8聽聽聽聽foo()聽{}聽//聽so聽only聽foo_impl聽can聽derive聽from聽foo
聽9聽聽聽聽const聽foo_impl聽*聽impl()聽const;
10聽聽聽聽foo_impl聽*聽impl();
11聽聽public:
12聽聽聽聽virtual~foo()聽{}
13聽聽聽聽//聽Factories
14聽聽聽聽static聽std::auto_ptr<foo>聽create(int聽value);
15聽聽聽聽//聽Interface
16聽聽聽聽int聽value()聽const;
17聽聽};
18
19聽聽//聽foo.cpp
20
21聽聽class聽foo_impl聽:聽public聽foo聽{
22聽聽聽聽friend聽class聽foo;
23聽聽聽聽//聽Constructors聽mirroring聽the聽factory聽functions聽in聽foo
24聽聽聽聽explicit聽foo_impl(int聽value)聽:聽value_(value)聽{}
25聽聽聽聽//聽Member聽data
26聽聽聽聽int聽value_;
27聽聽};
28
29聽聽inline聽const聽foo_impl聽*聽foo::impl()聽const聽{
30聽聽聽聽return聽static_cast<const聽foo_impl聽*>(this);
31聽聽}
32聽聽inline聽foo_impl聽*聽foo::impl()聽{
33聽聽聽聽return聽static_cast<foo_impl聽*>(this);
34聽聽}
35
36聽聽std::auto_ptr<foo>聽foo::create(int聽value)聽{
37聽聽聽聽return聽std::auto_ptr<foo>(new聽foo_impl(value));
38聽聽}
39
40聽聽int聽foo::value()聽const聽{聽return聽impl()->value_;聽}
41
42

Here, the destructor needs to be declared virtual foo so that std::auto_ptr<foo> calls foo_impl's destructor. If you use boost::shared_ptr<foo> instead, even that doesn't need to be virtual, because shared_ptr remembers how to call the correct destructor. (This doesn't improve performance or memory use, because shared_ptr is larger and slower than auto_ptr, but if you need to use shared_ptr anyway you may as well eliminate the virtual destructor.) -- BenHutchings


鍙傝冮槄璇伙細

Effective C++
http://c2.com/cgi/wiki?PimplIdiom
http://en.wikipedia.org/wiki/Opaque_pointer


]]>
Effective C++ - 09.緇濆涓嶈鍦ㄦ瀯閫犲拰鏋愭瀯榪囩▼涓皟鐢ㄨ櫄鍑芥暟http://m.tkk7.com/wenhl5656/archive/2010/07/28/327365.html鐖卞悆楸煎ご鐖卞悆楸煎ごWed, 28 Jul 2010 13:37:00 GMThttp://m.tkk7.com/wenhl5656/archive/2010/07/28/327365.htmlhttp://m.tkk7.com/wenhl5656/comments/327365.htmlhttp://m.tkk7.com/wenhl5656/archive/2010/07/28/327365.html#Feedback0http://m.tkk7.com/wenhl5656/comments/commentRss/327365.htmlhttp://m.tkk7.com/wenhl5656/services/trackbacks/327365.html瑕佺偣錛氱粷瀵逛笉搴旇鍦ㄦ瀯閫犲嚱鏁板拰鏋愭瀯鍑芥暟涓皟鐢ㄨ櫄鍑芥暟銆?br />
Derived Class瀵硅薄鍐呯殑Base Class鎴愬垎浼氬湪Derived Class鑷韓鎴愬垎琚瀯閫犱箣鍓嶆瀯閫犲畬鎴愩傚鏋淏ase Class鏋勯犲嚱鏁頒腑鏈夎櫄鍑芥暟錛坴irtual function錛夛紝璇irtual function緇濆涓嶄細涓嬮檷鍒癉erived Class灞備腑錛岃屾槸鐩存帴璋冪敤Base Class涓鍑芥暟錛岄氫織鐨勮錛屽嵆鈥斺斿湪Base Class鏋勯犳椂錛寁irtual function涓嶅啀琚綋鎴恦irtual function銆?br />
榪欐槸鍥犱負錛屽湪Base Class鏋勯犳湡闂達紝瀵硅薄鐨勭被鍨嬫槸Base Class鑰屼笉鏄疍erived Class銆備笉鍙槸铏氬嚱鏁頒細琚紪璇戝櫒瑙f瀽鑷矪ase Class涓紝鑻ヤ嬌鐢ㄨ繍琛屾湡綾諱俊鎭紙runtime type information錛屼緥濡俤ynamic_cast鍜宼ypeid錛夛紝涔熶細鎶婂璞¤涓築ase Class綾誨瀷銆傚悓鏍瘋繖涔熼傚悎浜庢瀽鏋勫嚱鏁般備竴鏃︾敱Derived Class鐨勬瀽鏋勫嚱鏁拌繘鍏ュ埌BaseClass鐨勬瀽鏋勫嚱鏁板悗錛屽璞″氨鎴愪負涓涓狟aseClass鐨勫璞′簡銆?br />


鐖卞悆楸煎ご 2010-07-28 21:37 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 久久久久久噜噜精品免费直播| 亚洲综合视频在线观看| 亚洲一区在线视频观看| 99爱在线观看免费完整版 | 午夜精品在线免费观看| 亚洲男人天堂2022| 一个人在线观看视频免费| 亚洲日本国产精华液| 日本黄网站动漫视频免费| 久久精品亚洲AV久久久无码 | 亚洲啪啪AV无码片| 国产日韩精品无码区免费专区国产 | 99久9在线|免费| 亚洲黄色三级网站| 亚洲免费人成视频观看| 亚洲av日韩av无码av| 青青草国产免费久久久91| 国产精品亚洲综合网站| 亚洲欧洲自拍拍偷精品 美利坚| xxxxx做受大片视频免费| 亚洲精品V欧洲精品V日韩精品| 免费污视频在线观看| 亚洲福利视频网站| 热99re久久精品精品免费| 黄页网址大全免费观看12网站| 亚洲日本一区二区一本一道 | www亚洲精品久久久乳| 亚洲无码日韩精品第一页| 日本一区午夜艳熟免费| 亚洲成a人片在线观| 真实乱视频国产免费观看| 国产高清对白在线观看免费91| 亚洲AV无码乱码国产麻豆穿越 | 18pao国产成视频永久免费| 亚洲av午夜精品无码专区| 全亚洲最新黄色特级网站 | 亚洲AV无码成人精品区在线观看| 免费观看无遮挡www的视频| 亚洲成av人在线观看网站| 亚洲色大成网站WWW久久九九 | 成人人观看的免费毛片|