锘??xml version="1.0" encoding="utf-8" standalone="yes"?>中文字幕亚洲专区,国产精一品亚洲二区在线播放,亚洲av午夜电影在线观看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 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 免费a在线观看播放| 亚洲AV性色在线观看| 成年美女黄网站色大免费视频| 99精品视频在线观看免费播放| 亚洲自偷自偷偷色无码中文| 免费在线观看一区| 亚洲国产成人爱av在线播放| 另类小说亚洲色图| 亚洲AV网站在线观看| 亚洲精品卡2卡3卡4卡5卡区| 成年网在线观看免费观看网址| 又粗又硬又黄又爽的免费视频| 爱情岛论坛亚洲品质自拍视频网站| 国产高清免费在线| 欧洲乱码伦视频免费国产| 区三区激情福利综合中文字幕在线一区亚洲视频1 | 亚洲日韩中文字幕天堂不卡 | 亚洲人成未满十八禁网站| 精品国产免费人成网站| 国产亚洲情侣一区二区无码AV| 精品国产呦系列在线观看免费| 亚洲日韩精品一区二区三区无码| 好久久免费视频高清| 亚洲人成网站在线播放影院在线| 亚洲免费观看网站| 亚洲6080yy久久无码产自国产| 日本中文一区二区三区亚洲| a级毛片高清免费视频就| 亚洲最大的成网4438| 无码专区永久免费AV网站| 亚洲hairy多毛pics大全| 国产亚洲一区区二区在线 | 久久精品国产精品亚洲艾草网| 亚洲国产高清国产拍精品| 免费看男女下面日出水视频| 亚洲va成无码人在线观看| 日本免费一本天堂在线| 青青操视频在线免费观看| 亚洲国产片在线观看| 亚洲AV无码一区二区三区在线观看 | 亚洲第一成年网站视频|