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

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>
            亚洲自拍三区| 欧美日韩在线播放一区| 国产精品久久二区二区| 久久精品99国产精品| 免费在线观看成人av| 亚洲免费视频在线观看| 久久九九电影| 亚洲一区二区三区乱码aⅴ蜜桃女| 在线亚洲美日韩| 91久久夜色精品国产九色| 亚洲视频999| 亚洲人成在线播放网站岛国| 亚洲午夜一区| 久久久久久尹人网香蕉| 亚洲免费网站| 久久久久网站| 欧美日韩三级视频| 亚洲精品免费网站| 日韩一区二区久久| 激情欧美亚洲| 亚洲美女精品成人在线视频| 国产日韩欧美亚洲| 亚洲国产精品美女| 国产精品久久婷婷六月丁香| 狂野欧美一区| 欧美亚韩一区| 久久亚洲捆绑美女| 欧美日韩国产精品| 每日更新成人在线视频| 欧美日韩一区二区视频在线| 久久精品亚洲热| 欧美日韩视频不卡| 久久久亚洲一区| 国产精品国内视频| 欧美黑人一区二区三区| 国产欧美在线| 一本色道久久综合亚洲精品按摩| 国内伊人久久久久久网站视频 | 国产精品久久久久久久久婷婷 | 午夜精品在线| 亚洲网站视频福利| 欧美1区免费| 麻豆精品在线观看| 国产一区二区在线观看免费| 99re66热这里只有精品4| 亚洲国产视频一区| 久久精品观看| 久久狠狠亚洲综合| 国产精品另类一区| 亚洲尤物在线| 午夜老司机精品| 国产精品99一区| 亚洲精品在线视频| 日韩视频在线一区二区| 猫咪成人在线观看| 免费成人在线观看视频| 伊人狠狠色j香婷婷综合| 亚洲欧洲99久久| 欧美一级播放| 国产亚洲观看| 欧美在线视频播放| 久久午夜激情| 亚洲国产高清aⅴ视频| 玖玖综合伊人| 亚洲高清资源综合久久精品| 亚洲黄色成人久久久| 久久综合给合| 亚洲激情成人| 一区二区三区.www| 欧美午夜片在线观看| 亚洲午夜精品久久| 亚洲影视九九影院在线观看| 欧美三级午夜理伦三级中文幕| 亚洲精品乱码久久久久久蜜桃麻豆 | 亚洲免费一级电影| 国产区在线观看成人精品| 亚洲欧美成aⅴ人在线观看| 欧美在线啊v| 在线免费观看欧美| 欧美国产日韩一二三区| 夜夜精品视频一区二区| 欧美一二区视频| 精品91视频| 欧美 日韩 国产在线| 亚洲精品专区| 久久精品国产亚洲一区二区| 韩日精品中文字幕| 你懂的国产精品永久在线| 亚洲全黄一级网站| 欧美有码在线观看视频| 精品51国产黑色丝袜高跟鞋| 米奇777在线欧美播放| 一本色道久久综合亚洲91| 久久国产直播| 日韩亚洲成人av在线| 国产精品国产三级国产专区53| 亚洲欧美日韩国产中文在线| 久久综合国产精品台湾中文娱乐网| 亚洲国产成人精品久久久国产成人一区 | 亚洲女性裸体视频| 国产一区二区在线观看免费播放| 久久九九国产精品| 欧美激情91| 亚洲一区二区三区免费视频| 影音先锋日韩资源| 国产精品久久久久久久久果冻传媒| 久久久久久久久综合| 在线视频精品一区| 欧美成人a视频| 久久福利电影| 中文在线资源观看视频网站免费不卡| 国产欧美视频一区二区| 欧美韩日一区二区| 久久精品一区二区三区不卡| 一区二区三区精品视频| 欧美国产日本韩| 久久在线视频在线| 欧美影院成人| 亚洲欧美国产精品桃花| 亚洲美女91| 亚洲国产日韩综合一区| 国产在线精品自拍| 国产情侣一区| 国产精品久久久一区二区三区| 欧美精品高清视频| 免费一级欧美片在线播放| 久久欧美中文字幕| 亚洲欧美日韩国产成人精品影院| 亚洲精品护士| 亚洲人成毛片在线播放女女| 欧美成人黄色小视频| 久久午夜国产精品| 久久这里只有| 久久久久在线观看| 久久久久99| 久久视频在线免费观看| 久久精品欧美日韩精品| 欧美一区三区二区在线观看| 亚洲一区二区三区国产| 这里只有精品视频| 亚洲婷婷综合色高清在线| 一区二区三区高清| 亚洲香蕉伊综合在人在线视看| 夜久久久久久| 亚洲视频在线一区| 亚洲一区二区三区四区五区午夜| 亚洲视频一区二区免费在线观看| 日韩视频在线观看| 亚洲一区二区在线看| 亚洲免费在线视频| 欧美在线观看一二区| 久久久久久久久久码影片| 久久久精彩视频| 欧美成人免费在线视频| 亚洲精品你懂的| 亚洲人成高清| 亚洲一区二区三区激情| 欧美一区二区三区四区高清 | 亚洲精品乱码视频| 亚洲视频二区| 久久国产精品一区二区三区四区| 久久三级福利| 欧美日韩精品免费观看视一区二区 | 中国亚洲黄色| 久久99在线观看| 欧美高清视频www夜色资源网| 亚洲第一精品影视| 亚洲一级免费视频| 久久久久久久一区二区| 欧美韩国日本一区| 国产精品嫩草99av在线| 国内精品久久久久影院色| 亚洲欧洲精品一区二区精品久久久| 9i看片成人免费高清| 欧美一区二区三区四区视频| 欧美96在线丨欧| 一区二区三区日韩精品| 久久久欧美精品| 国产精品v日韩精品v欧美精品网站| 国产欧美婷婷中文| 亚洲卡通欧美制服中文| 久久久精品2019中文字幕神马| 亚洲青色在线| 久久午夜电影| 国产精品日本精品| 日韩亚洲欧美精品| 久久综合国产精品台湾中文娱乐网| 日韩亚洲精品在线| 鲁大师影院一区二区三区| 国产农村妇女精品一区二区| 日韩亚洲欧美一区| 牛牛国产精品| 久久国产精品99国产精| 国产精品久线观看视频| 99re6这里只有精品| 免费看成人av| 欧美一区二区三区精品| 国产精品久久久久久一区二区三区| 亚洲国产影院| 亚洲美女在线看|