锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲成人一级电影,情人伊人久久综合亚洲,亚洲电影在线播放http://www.tkk7.com/wenhl5656/category/45754.html鎯寵搗鍜岃佽倴鐮旂┒涓柇鐨勬棩瀛愶紝鍊嶈娓╅Θzh-cnMon, 09 Aug 2010 03:56:44 GMTMon, 09 Aug 2010 03:56:44 GMT60pImpl Idiomhttp://www.tkk7.com/wenhl5656/archive/2010/08/07/328217.html鐖卞悆楸煎ご鐖卞悆楸煎ごSat, 07 Aug 2010 14:58:00 GMThttp://www.tkk7.com/wenhl5656/archive/2010/08/07/328217.htmlhttp://www.tkk7.com/wenhl5656/comments/328217.htmlhttp://www.tkk7.com/wenhl5656/archive/2010/08/07/328217.html#Feedback0http://www.tkk7.com/wenhl5656/comments/commentRss/328217.htmlhttp://www.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://www.tkk7.com/wenhl5656/archive/2010/07/28/327365.html鐖卞悆楸煎ご鐖卞悆楸煎ごWed, 28 Jul 2010 13:37:00 GMThttp://www.tkk7.com/wenhl5656/archive/2010/07/28/327365.htmlhttp://www.tkk7.com/wenhl5656/comments/327365.htmlhttp://www.tkk7.com/wenhl5656/archive/2010/07/28/327365.html#Feedback0http://www.tkk7.com/wenhl5656/comments/commentRss/327365.htmlhttp://www.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 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 久久免费观看视频| sss日本免费完整版在线观看| 四虎影视在线影院在线观看免费视频 | 亚洲综合激情九月婷婷| 免费国产在线视频| 久久亚洲AV无码精品色午夜麻| 99热在线日韩精品免费| 亚洲国产日韩一区高清在线| 免费无码一区二区三区| 亚洲一区动漫卡通在线播放| 波多野结衣在线免费观看| 亚洲欧美黑人猛交群| 国产在线观看免费不卡| 一级做a爱过程免费视| 久久久久久久尹人综合网亚洲| 久久国产精品免费网站| 亚洲成年人电影在线观看| 成人性生交大片免费看无遮挡| 亚洲精品久久无码| 亚洲综合av永久无码精品一区二区| a级毛片高清免费视频| 在线观看亚洲人成网站| 日本黄色免费观看| 一级毛片免费在线观看网站| 亚洲高清国产拍精品26U| 啦啦啦完整版免费视频在线观看 | 桃子视频在线观看高清免费完整 | 怡红院免费全部视频在线视频| 色婷婷亚洲十月十月色天| 成人奭片免费观看| 欧洲精品码一区二区三区免费看| 亚洲色婷婷一区二区三区| 7723日本高清完整版免费| 久久亚洲中文无码咪咪爱| 亚洲人成色777777在线观看| 亚色九九九全国免费视频| 七次郎成人免费线路视频| 亚洲精品一区二区三区四区乱码| 日本一道在线日本一道高清不卡免费 | 久久精品国产亚洲av高清漫画| 日韩免费一级毛片|