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

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 閱讀(397) 評(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一本 | 99成人在线| 亚洲一区日韩在线| 国产精品一区二区你懂的| 久久福利视频导航| 欧美黄色免费网站| 夜夜嗨网站十八久久| 国产精品欧美一区二区三区奶水| 亚洲欧美日韩精品一区二区| 美女视频黄免费的久久| 日韩天堂在线观看| 国产麻豆9l精品三级站| 久久精品国产一区二区三区| 亚洲国产中文字幕在线观看| 中文国产成人精品久久一| 国产日韩精品在线观看| 欧美成人四级电影| 午夜精品成人在线| 亚洲激情在线观看| 久久av一区二区三区| 亚洲精品一二区| 国产精品人人做人人爽| 欧美α欧美αv大片| 亚洲专区免费| 亚洲激情婷婷| 久久午夜电影| 中文有码久久| 亚洲国产精品第一区二区三区 | 国产啪精品视频| 欧美承认网站| 久久国产欧美日韩精品| 一个色综合av| 亚洲国产成人精品女人久久久| 欧美亚洲网站| 一本久久a久久精品亚洲| 一区在线观看视频| 国产乱理伦片在线观看夜一区| 欧美成人中文| 欧美自拍丝袜亚洲| 亚洲综合二区| 亚洲日本中文字幕| 欧美va日韩va| 久久精品欧美日韩| 午夜亚洲福利| 亚洲一本视频| 99国产精品久久久| 亚洲国产精品成人精品| 国产日产欧美一区| 国产精品天天摸av网| 欧美日韩国产成人在线| 欧美国产日韩免费| 免费观看成人www动漫视频| 久久国产精品久久国产精品| 亚洲一区二区在线看| 99视频超级精品| 亚洲精品看片| 亚洲精品久久久一区二区三区| 欧美国产一区视频在线观看| 另类尿喷潮videofree| 久久精品国产999大香线蕉| 欧美一级片一区| 午夜精品在线观看| 亚洲欧美日韩精品一区二区 | 美女91精品| 久久综合久久久久88| 久久久久这里只有精品| 久久精品国产亚洲a| 久久国产欧美精品| 久久精品一区二区三区四区| 欧美中文字幕| 久久精品麻豆| 久久亚洲精品一区| 麻豆精品视频在线| 欧美激情第三页| 亚洲国产精品悠悠久久琪琪| 亚洲人成在线观看一区二区| 91久久国产自产拍夜夜嗨| 亚洲国产三级在线| 日韩午夜在线视频| 亚洲视频1区| 亚洲欧洲av一区二区三区久久| 亚洲一区二区在线免费观看视频| 亚洲欧美日韩国产中文| 欧美在线观看你懂的| 久久色在线观看| 欧美大片国产精品| 欧美日韩视频在线一区二区| 国产精品久久一级| 国内成+人亚洲| 亚洲激情网站免费观看| 艳女tv在线观看国产一区| 亚洲欧美国产一区二区三区| 欧美伊人久久久久久久久影院 | 亚洲香蕉伊综合在人在线视看| 亚洲少妇诱惑| 欧美在线三区| 欧美精品99| 国产欧美日韩综合一区在线播放| 黑人操亚洲美女惩罚| 日韩一级大片| 久久se精品一区二区| 免费试看一区| 99精品热视频| 欧美一区二区女人| 欧美激情一区二区三区| 国产精品五月天| 亚洲第一区色| 亚洲网在线观看| 久久免费国产精品1| 亚洲免费播放| 久久久亚洲影院你懂的| 欧美日韩一区在线视频| 黄色成人av| 亚洲一区二区三区欧美| 蜜臀va亚洲va欧美va天堂| 亚洲看片免费| 久久久久久久综合狠狠综合| 欧美午夜一区| 亚洲人成网站在线播| 欧美在线地址| 亚洲精品无人区| 久久久久久久久久久一区 | 国产亚洲视频在线观看| 日韩系列在线| 欧美不卡一区| 欧美一区激情| 欧美性天天影院| 亚洲精选在线观看| 久久久青草婷婷精品综合日韩| 亚洲精品一品区二品区三品区| 久久精品一二三| 国产精品一级久久久| 99re成人精品视频| 欧美成人精品一区二区三区| 亚洲免费小视频| 欧美日韩情趣电影| 亚洲精品一区二区三区樱花| 久久一区二区精品| 亚洲男人第一av网站| 欧美日韩中文另类| 日韩亚洲国产欧美| 欧美成人亚洲| 久久午夜精品| 在线观看成人av| 久久婷婷蜜乳一本欲蜜臀| 亚洲欧美日韩一区二区| 国产精品乱码妇女bbbb| 亚洲午夜久久久| 亚洲精品一区在线观看| 欧美成人资源| 亚洲乱码国产乱码精品精可以看| 欧美福利在线观看| 乱码第一页成人| 亚洲人成网站精品片在线观看| 欧美+亚洲+精品+三区| 久久精品日韩| 激情一区二区| 欧美韩日视频| 欧美大片第1页| 99视频一区| 日韩小视频在线观看专区| 欧美精品啪啪| 亚洲性夜色噜噜噜7777| 99re在线精品| 国产精品v片在线观看不卡| 亚洲网站视频福利| aa级大片欧美| 国产精品一区二区欧美| 久久精品一区二区三区不卡| 欧美在线播放一区| 亚洲高清自拍| 日韩亚洲不卡在线| 欧美网站在线观看| 午夜一区二区三区不卡视频| 亚洲欧美第一页| 国模套图日韩精品一区二区| 欧美va亚洲va日韩∨a综合色| 久久综合九色九九| 亚洲美女黄网| 亚洲一区在线观看免费观看电影高清 | 国产精品久久久久久久久借妻| 午夜欧美电影在线观看| 欧美一区二区三区免费大片| 狠狠噜噜久久| 亚洲人成毛片在线播放| 国产精品久久久久久久浪潮网站| 久久成人国产| 久久亚洲欧美| 亚洲在线一区| 久久精品视频在线播放| 亚洲精品久久久久| 亚洲一卡久久| 亚洲国产日韩欧美一区二区三区| 亚洲精品一区二区三区av|