青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

EverSpring working shop

To pursue creative ideas based on nature.

統計

留言簿(1)

他山之石

閱讀排行榜

評論排行榜

Some notes about dynamic polymorphism (by virtual) and static polymorphism (by template)

The time and space cost by the late binding (dynamic polymorphism), which is mainly implemented by Virtual Functions, is more than the static polymorphism, mainly implemented by the Template usage. This is because the compiler needs to allocate speical VPTR and VTABLE for each class with virtual function denoted. And duirng the compiling time, the original code is expanded by adding the code locating the virtual functiona address in the VTABLE, at each place the base class pointer/reference are passed?as parameter in?other function call. Finally, at the running time, such extra?code absolutely costs extra time, especially when the base class pointer/referece are passed as parms very frequently.? We can consider to use the template in such sitations like:
    • The context is using the Set of the objects instead of the pointer/reference, and the objects of this set have common behavior at a level of abstraction. The typical application is the Containers design in the STL.
    • The algorithem or behavior of different objects has some common attribute and this common attributes can be determined at compiling time.
    • Policy based programming, and such policy selection can be determined by the client at the compiling time. Refer to MCppD.
    • Very senstive to the requirements on efficiency of time or space.
Must be noted: The bahavior must be determined at the compiling time if using the Template Polymorphism. This means the the client must have the type information explicitly during the code construction time. From this point, we may say the in Template Polymorphism, the CLIENT is the usually in design scope of application because it?is?responsible for the Template Specialization. As to the Dynamic, the?CLIENT?is more in the design scope for the framework, not care of the concrete type information in operation.
Here give an example explaining the usage of the dynamic/static polymorphism:
?
#include <iostream>
using namespace std;
?

/*
?* =====================================================================================
?*??????? Class:? base_d
?*? Description:?
?* =====================================================================================
?*/
class base_d
{
?
? public:
?
??? /* ====================? LIFECYCLE?? ========================================= */
?
??? base_d ();? /* constructor */
?
??? /* Use compiler-generated copy constructor, assignment operator and destructor */
?
??? /* ====================? OPERATORS?? ========================================= */
?
??? /* ====================? OPERATIONS? ========================================= */
??? virtual void dosomething() = 0;
??? /* ====================? ACCESS????? ========================================= */
?
??? /* ====================? INQUIRY???? ========================================= */
?
? protected:
?
? private:
?
}; /* -----? end of class? base_d? ----- */
?
/*
?*--------------------------------------------------------------------------------------
?*?????? Class:? base_d
?*????? Method:? base_d
?* Description:? constructor
?*--------------------------------------------------------------------------------------
?*/
base_d::base_d ()
{
}? /* -----? end of method base_d::base_d? (constructor)? ----- */
?

/*
?* =====================================================================================
?*??????? Class:? client_d
?*? Description:?
?* =====================================================================================
?*/
class client_d
{
?
? public:
?
??? /* ====================? LIFECYCLE?? ========================================= */
?
??? client_d (base_d*);? /* constructor */
?
??? /* Use compiler-generated copy constructor, assignment operator and destructor */
?
??? /* ====================? OPERATORS?? ========================================= */
?
??? /* ====================? OPERATIONS? ========================================= */
?
??? /* ====================? ACCESS????? ========================================= */
??? void get_do();
??? /* ====================? INQUIRY???? ========================================= */
?
? protected:
?
? private:
??? base_d* ptr_b;
?
}; /* -----? end of class? client_d? ----- */
?
/*
?*--------------------------------------------------------------------------------------
?*?????? Class:? client_d
?*????? Method:? client_d
?* Description:? constructor
?*--------------------------------------------------------------------------------------
?*/
client_d::client_d (base_d* pb):ptr_b(pb)
{
}? /* -----? end of method client_d::client_d? (constructor)? ----- */
?

void
client_d::get_do (? )
{
?ptr_b->dosomething();
}??/* -----? end of method client_d::get_do? ----- */
?

/*
?* =====================================================================================
?*??????? Class:? der1_d
?*? Description:?
?* =====================================================================================
?*/
class der1_d : public base_d
{
?
? public:
?
??? /* ====================? LIFECYCLE?? ========================================= */
?
??? der1_d ();? /* constructor */
?
??? /* Use compiler-generated copy constructor, assignment operator and destructor */
?
??? /* ====================? OPERATORS?? ========================================= */
?
??? /* ====================? OPERATIONS? ========================================= */
??? virtual void dosomething();
??? /* ====================? ACCESS????? ========================================= */
?
??? /* ====================? INQUIRY???? ========================================= */
?
? protected:
?
? private:
?
}; /* -----? end of class? der1_d? ----- */
?
/*
?*--------------------------------------------------------------------------------------
?*?????? Class:? der1_d
?*????? Method:? der1_d
?* Description:? constructor
?*--------------------------------------------------------------------------------------
?*/
der1_d::der1_d ()
{
}? /* -----? end of method der1_d::der1_d? (constructor)? ----- */
?

void
der1_d::dosomething (? )
{
??? cout <<"\n this is der1_d is doing something!\n";
}??/* -----? end of method der1_d::dosoming? ----- */
?

/*
?* =====================================================================================
?*??????? Class:? der2_d
?*? Description:?
?* =====================================================================================
?*/
class der2_d : public base_d
{
?
? public:
?
??? /* ====================? LIFECYCLE?? ========================================= */
?
??? der2_d ();? /* constructor */
?
??? /* Use compiler-generated copy constructor, assignment operator and destructor */
?
??? /* ====================? OPERATORS?? ========================================= */
?
??? /* ====================? OPERATIONS? ========================================= */
??? virtual void dosomething();
??? /* ====================? ACCESS????? ========================================= */
?
??? /* ====================? INQUIRY???? ========================================= */
?
? protected:
?
? private:
?
}; /* -----? end of class? der2_d? ----- */
?
/*
?*--------------------------------------------------------------------------------------
?*?????? Class:? der2_d
?*????? Method:? der2_d
?* Description:? constructor
?*--------------------------------------------------------------------------------------
?*/
der2_d::der2_d ()
{
}? /* -----? end of method der2_d::der2_d? (constructor)? ----- */
?

void
der2_d::dosomething (? )
{
??? cout <<"\n this is der2_d is doing something!\n";
}??/* -----? end of method der2_d::dosomething? ----- */
?

/*
?* =====================================================================================
?*??????? Class:? client_s
?*? Description:?
?* =====================================================================================
?*/
template < class T >
class client_s
{
?
? public:
?
??? /* ====================? LIFECYCLE?? ========================================= */
?
??? client_s (T* );?? /* constructor */
?
??? /* Use compiler-generated copy constructor, assignment operator and destructor */
?
??? /* ====================? OPERATORS?? ========================================= */
?
??? /* ====================? OPERATIONS? ========================================= */
??? void get_do();
??? /* ====================? ACCESS????? ========================================= */
?
??? /* ====================? INQUIRY???? ========================================= */
?
? protected:
?
? private:
??? T* ptr_t;
}; /* ----------? end of template class? client_s? ---------- */
?
/*
?*--------------------------------------------------------------------------------------
?*?????? Class:? client_s
?*????? Method:? client_s
?* Description:?
?*--------------------------------------------------------------------------------------
?*/
template < class T >
client_s < T >::client_s (T* pt):ptr_t(pt)
{
}? /* ----------? end of constructor of template class client_s? ---------- */
?
template < class T>
void
client_s<T>::get_do (? )
{
?ptr_t->dosomething();
}??/* -----? end of method client_s::get_do? ----- */
?

/*
?* =====================================================================================
?*??????? Class:? der1_s
?*? Description:?
?* =====================================================================================
?*/
class der1_s
{
?
? public:
?
??? /* ====================? LIFECYCLE?? ========================================= */
?
??? der1_s ();? /* constructor */
?
??? /* Use compiler-generated copy constructor, assignment operator and destructor */
?
??? /* ====================? OPERATORS?? ========================================= */
?
??? /* ====================? OPERATIONS? ========================================= */
??? void dosomething();
??? /* ====================? ACCESS????? ========================================= */
?
??? /* ====================? INQUIRY???? ========================================= */
?
? protected:
?
? private:
?
}; /* -----? end of class? der1_s? ----- */
?
/*
?*--------------------------------------------------------------------------------------
?*?????? Class:? der1_s
?*????? Method:? der1_s
?* Description:? constructor
?*--------------------------------------------------------------------------------------
?*/
der1_s::der1_s ()
{
}? /* -----? end of method der1_s::der1_s? (constructor)? ----- */
?

void
der1_s::dosomething (? )
{
??? cout <<"\n this is der1_s doing something!\n" ;
}??/* -----? end of method der1_s::dosomething? ----- */
?

/*
?* =====================================================================================
?*??????? Class:? der2_s
?*? Description:?
?* =====================================================================================
?*/
class der2_s
{
?
? public:
?
??? /* ====================? LIFECYCLE?? ========================================= */
?
??? der2_s ();? /* constructor */
?
??? /* Use compiler-generated copy constructor, assignment operator and destructor */
?
??? /* ====================? OPERATORS?? ========================================= */
?
??? /* ====================? OPERATIONS? ========================================= */
??? void dosomething();
??? /* ====================? ACCESS????? ========================================= */
?
??? /* ====================? INQUIRY???? ========================================= */
?
? protected:
?
? private:
?
}; /* -----? end of class? der2_s? ----- */
?
/*
?*--------------------------------------------------------------------------------------
?*?????? Class:? der2_s
?*????? Method:? der2_s
?* Description:? constructor
?*--------------------------------------------------------------------------------------
?*/
der2_s::der2_s ()
{
}? /* -----? end of method der2_s::der2_s? (constructor)? ----- */
?

void
der2_s::dosomething (? )
{
?cout<<"\n this is der2_s doing something!\n" ;
}??/* -----? end of method der2_s::dosomething? ----- */
?

int main()
{
?? // Dynamic Polymorphism example:
?? base_d * ptr_1 = new der1_d;
?? base_d * ptr_2 = new der2_d;
?
?? client_d * ptr_c_1 = new client_d(ptr_1);
?? client_d * ptr_c_2 = new client_d(ptr_2);
?
?? ptr_c_1 -> get_do();
?? ptr_c_2 -> get_do();
?
?? // Static Polymorphism example:
?? der1_s * ptr_3 = new der1_s;
?? der2_s * ptr_4 = new der2_s;
??
?? client_s<der1_s> obj_client_1(ptr_3);
?? client_s<der2_s> obj_client_2(ptr_4);
?
?? obj_client_1.get_do();
?? obj_client_2.get_do();
?
?? return 0;
}
testing out:
[alexzh@alexzhang_lnx d_s_poly]$ ./a.out
?
?this is der1_d is doing something!
?
?this is der2_d is doing something!
?
?this is der1_s doing something!
?
?this is der2_s doing something!

posted on 2009-03-08 17:25 everspring79 閱讀(392) 評論(0)  編輯 收藏 引用 所屬分類: Notes

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲国内精品| 亚洲一区二区黄| 在线观看福利一区| 亚洲一区激情| 亚洲欧洲一区二区天堂久久| 欧美一级午夜免费电影| 国产精品国产自产拍高清av王其| 亚洲国产你懂的| 免费h精品视频在线播放| 欧美一区二区三区视频| 国产精品普通话对白| 亚洲视频成人| 一区二区高清在线观看| 欧美视频导航| 亚洲欧美视频| 亚洲一本大道在线| 国产精品午夜电影| 欧美在线影院| 久久精品国产在热久久| 激情文学综合丁香| 欧美成人免费全部| 久久尤物视频| 亚洲精品一级| 日韩写真在线| 国产精品女人网站| 欧美在线综合| 久久蜜桃精品| 亚洲毛片在线看| 日韩午夜黄色| 国产农村妇女毛片精品久久莱园子 | 亚洲第一天堂av| 欧美激情成人在线| 亚洲一区二区三区在线播放| 亚洲一区二区综合| 国产一二三精品| 免费欧美电影| 欧美日韩一区二区视频在线 | 一区二区高清在线观看| 国产欧美精品一区二区三区介绍| 久久久久久国产精品mv| 美女被久久久| 亚洲综合激情| 久久偷窥视频| 亚洲嫩草精品久久| 久久午夜激情| 亚洲一区二区久久| 久久久久久夜| 亚洲午夜一级| 久久免费视频网站| 亚洲一区二区三区在线| 久久精品一区二区国产| 一区二区高清视频| 欧美一区二区在线看| 日韩亚洲视频| 久久精品人人爽| 亚洲尤物精选| 欧美成人福利视频| 久久精品视频导航| 欧美无砖砖区免费| 欧美激情偷拍| 黑人巨大精品欧美黑白配亚洲| 亚洲乱码视频| 亚洲国产综合视频在线观看| 亚洲欧美日韩系列| 亚洲一区国产视频| 欧美久久久久久久久| 你懂的一区二区| 国产偷久久久精品专区| 一二三区精品福利视频| 日韩视频中文字幕| 麻豆国产精品va在线观看不卡| 欧美中文字幕视频| 国产精品国产三级国产专播品爱网| 毛片一区二区三区| 国产亚洲欧美一区在线观看| aⅴ色国产欧美| 日韩一级成人av| 免费成人高清| 欧美成人情趣视频| 在线观看日韩一区| 久久精品亚洲精品| 久久久久久亚洲综合影院红桃| 国产精品视频一区二区三区| 一本久道综合久久精品| 一本色道久久99精品综合| 男女精品网站| 亚洲高清免费视频| 亚洲三级电影在线观看 | 国产综合亚洲精品一区二| 亚洲女ⅴideoshd黑人| 亚洲专区一区二区三区| 欧美日韩中文字幕在线视频| 亚洲精品乱码久久久久久蜜桃91 | 亚洲丁香婷深爱综合| 午夜精品视频| 久久成人精品视频| 国产亚洲欧美日韩日本| 新67194成人永久网站| 欧美呦呦网站| 国产一区二区三区黄视频| 欧美一二三视频| 久久亚洲精品一区| 亚洲电影有码| 欧美激情视频一区二区三区在线播放| 欧美激情一区二区在线| 99综合在线| 欧美午夜精品理论片a级大开眼界 欧美午夜精品理论片a级按摩 | 一本色道久久综合| 欧美午夜电影在线| 亚洲欧美日韩中文播放| 久久中文字幕一区| 亚洲黄色三级| 欧美三级视频在线播放| 亚洲欧美日本视频在线观看| 久久久亚洲国产美女国产盗摄| 激情婷婷久久| 欧美久久久久久蜜桃| 亚洲小说春色综合另类电影| 久久久久久久综合日本| 91久久线看在观草草青青| 欧美少妇一区二区| 久久精品日韩欧美| 亚洲精品影院| 久久久亚洲午夜电影| av成人免费在线观看| 国产欧美日韩视频一区二区| 免费精品视频| 亚洲欧美激情一区| 欧美国产日韩二区| 亚洲免费综合| 亚洲欧洲免费视频| 国产日韩欧美综合一区| 欧美成人国产| 欧美在线免费观看视频| 亚洲韩国日本中文字幕| 欧美一区二区三区视频在线| 亚洲日本在线观看| 国产午夜精品全部视频播放| 欧美激情第4页| 久久国产高清| 9l视频自拍蝌蚪9l视频成人| 欧美风情在线| 久久久久久999| 亚洲一区精品电影| 91久久精品网| 狠狠网亚洲精品| 欧美性开放视频| 你懂的视频一区二区| 欧美一区二区在线免费观看| 9国产精品视频| 亚洲黄色高清| 欧美sm重口味系列视频在线观看| 性久久久久久| 亚洲香蕉成视频在线观看| 最新国产成人av网站网址麻豆| 国产亚洲精品v| 国产精品亚洲综合| 国产精品国产三级国产专播品爱网| 欧美国产一区二区三区激情无套| 久久精品国产亚洲一区二区三区| 亚洲在线播放| 亚洲香蕉网站| 亚洲一区免费网站| 亚洲视频欧美在线| 夜夜嗨一区二区| 99国产精品自拍| 99精品国产在热久久婷婷| 亚洲级视频在线观看免费1级| 欧美成人午夜剧场免费观看| 老色批av在线精品| 久热精品视频在线免费观看 | 亚洲性人人天天夜夜摸| 99亚洲视频| 亚洲私人影院| 亚洲一区精彩视频| 亚洲欧美在线aaa| 午夜电影亚洲| 欧美一级黄色录像| 欧美一区二区三区日韩| 欧美在线视频观看免费网站| 欧美有码视频| 久久久精品国产免大香伊| 久久久777| 欧美成人第一页| 欧美日韩少妇| 国产精品久久久久久久免费软件| 国产精品久久久久久户外露出| 国产精品hd| 国产日韩亚洲| 在线免费观看日本欧美| 最新国产成人av网站网址麻豆| 日韩视频免费观看高清完整版| 日韩亚洲欧美高清| 午夜精品久久久久久久久久久| 欧美有码视频| 欧美成人一区二区三区在线观看 | 亚洲综合好骚| 欧美中文字幕在线| 蜜臀av性久久久久蜜臀aⅴ四虎| 欧美激情按摩|