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

EverSpring working shop

To pursue creative ideas based on nature.

統(tǒng)計(jì)

留言簿(1)

他山之石

閱讀排行榜

評(píng)論排行榜

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 閱讀(388) 評(píng)論(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>
            一区二区三区.www| 欧美影院在线| 亚洲国产另类久久精品| 欧美一区二区三区啪啪| 国产色爱av资源综合区| 久久久午夜电影| 免费久久99精品国产自| 999亚洲国产精| 这里只有精品电影| 国产美女在线精品免费观看| 久久福利一区| 久久五月婷婷丁香社区| 日韩视频一区二区三区在线播放| 亚洲精品在线视频观看| 国产精品日韩精品欧美精品| 玖玖玖国产精品| 免费久久99精品国产自在现线| 一区二区黄色| 午夜精品久久久久久久99樱桃| 亚洲电影免费| 一区二区三区日韩在线观看 | 欧美激情性爽国产精品17p| 欧美韩日一区二区| 欧美有码视频| 欧美岛国激情| 久久精品成人一区二区三区| 欧美电影在线观看完整版| 欧美一区二区三区啪啪| 欧美电影免费观看大全| 欧美一区中文字幕| 欧美黄色成人网| 久久精品视频免费播放| 欧美日韩的一区二区| 久久久亚洲国产天美传媒修理工| 欧美精品日韩精品| 久久亚洲午夜电影| 欧美色视频一区| 欧美激情亚洲激情| 国产日韩欧美91| 一区二区av| 亚洲激情黄色| 久久久久99| 久久精品99国产精品日本 | 久久综合九色综合欧美就去吻| 久久精品综合| 欧美怡红院视频| 欧美天天在线| 亚洲精品少妇| 亚洲裸体视频| 卡通动漫国产精品| 久久久精品国产一区二区三区| 欧美日韩一区二区三区| 亚洲国产91精品在线观看| 红桃视频国产精品| 欧美一区二区精美| 久久精品女人天堂| 国产精品一区在线观看你懂的| 一本色道久久99精品综合| 亚洲精品久久嫩草网站秘色| 久久另类ts人妖一区二区| 久久久国产91| 国模叶桐国产精品一区| 午夜亚洲福利在线老司机| 亚洲欧美日韩综合aⅴ视频| 欧美日韩一区二区三区在线 | 欧美激情中文字幕一区二区| 狠狠色丁香婷婷综合久久片| 欧美自拍偷拍| 老司机成人网| 亚洲电影成人| 欧美激情在线免费观看| 亚洲精品乱码久久久久久日本蜜臀 | 久久久久久国产精品mv| 久久青草欧美一区二区三区| 永久免费毛片在线播放不卡| 久久夜色精品国产| 欧美激情一区二区三区蜜桃视频| 亚洲精品国产精品国自产观看浪潮| 欧美高清视频一区二区三区在线观看| 欧美激情网站在线观看| 99综合电影在线视频| 欧美香蕉大胸在线视频观看| 亚洲男人的天堂在线| 久久婷婷麻豆| 亚洲美女视频网| 国产精品久久久久9999吃药| 亚洲欧美国产日韩中文字幕| 久久久久久一区| 亚洲精品乱码久久久久久蜜桃麻豆 | 久久久人成影片一区二区三区观看 | 最新国产の精品合集bt伙计| 欧美激情1区2区3区| 99综合在线| 久久久国产一区二区| 亚洲国产日韩一区二区| 欧美日韩综合另类| 欧美一区二区免费| 亚洲激情一区二区| 欧美综合国产精品久久丁香| 亚洲电影毛片| 国产精品亚洲欧美| 免费日韩av| 亚洲欧美日本日韩| 亚洲国产欧美一区二区三区久久| 亚洲欧美成人一区二区三区| 一区免费观看视频| 欧美午夜精品久久久| 久久久久在线| 亚洲欧洲精品成人久久奇米网| 欧美体内谢she精2性欧美| 久久久99免费视频| 中文国产成人精品| 亚洲高清资源| 久久婷婷国产麻豆91天堂| 一区二区三区www| 伊人一区二区三区久久精品| 国产精品高潮呻吟久久av无限| 久久经典综合| 亚洲男人的天堂在线观看| 亚洲动漫精品| 美日韩精品视频| 欧美中文字幕在线观看| 一区二区三区日韩| 亚洲欧洲另类国产综合| 国产日韩视频| 国产精品有限公司| 国产精品mm| 欧美美女操人视频| 免费不卡视频| 久久午夜av| 久久综合成人精品亚洲另类欧美| 亚洲欧美视频在线| 亚洲免费一在线| 亚洲一区二区三区涩| 99xxxx成人网| 日韩一级视频免费观看在线| 亚洲黄色一区| 亚洲区第一页| 亚洲精品视频免费观看| 亚洲国产专区| 91久久精品视频| 亚洲二区在线视频| 亚洲高清在线精品| 亚洲国产精品传媒在线观看 | 99精品欧美一区二区三区综合在线 | 麻豆精品视频在线| 久久亚洲综合色| 免费久久99精品国产自| 老鸭窝91久久精品色噜噜导演| 久久久国际精品| 久久综合久色欧美综合狠狠 | 日韩天堂在线视频| 一级成人国产| 小黄鸭精品aⅴ导航网站入口| 亚洲一区二区三区在线播放| 午夜精品久久久久久久| 久久成人免费电影| 老司机亚洲精品| 最近中文字幕mv在线一区二区三区四区 | 欧美一区二区免费观在线| 欧美一级免费视频| 久久久久久网址| 亚洲成色999久久网站| 亚洲国产一区在线| 亚洲午夜视频在线观看| 小黄鸭精品aⅴ导航网站入口| 久久精品夜色噜噜亚洲aⅴ| 美女任你摸久久| 欧美日韩在线观看一区二区| 国产精品毛片va一区二区三区| 国内成+人亚洲| 亚洲精选成人| 欧美亚洲综合在线| 欧美国产日韩a欧美在线观看| 亚洲日本中文字幕免费在线不卡| 亚洲一区二区三区精品视频| 欧美一区二区三区的| 美女999久久久精品视频| 欧美日韩一二三四五区| 国精产品99永久一区一区| 亚洲清纯自拍| 久久超碰97中文字幕| 亚洲国产精品va在线观看黑人| 中国成人黄色视屏| 麻豆亚洲精品| 亚洲美女av网站| 久久精品国产99国产精品| 欧美激情综合色| 韩日视频一区| 亚洲伊人伊色伊影伊综合网| 久久欧美中文字幕| 亚洲午夜女主播在线直播| 久久亚洲私人国产精品va媚药| 国产精品每日更新| 亚洲精品久久久蜜桃| 久久久在线视频| 亚洲女同精品视频| 欧美精品v日韩精品v国产精品| 国语精品中文字幕| 欧美一级片一区|