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

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>
            亚洲欧美激情诱惑| 最新亚洲一区| 久久久久久尹人网香蕉| 欧美在线免费看| 狠狠色丁香久久婷婷综合_中| 久久久国产一区二区三区| 久久国内精品视频| 亚洲欧洲一区二区在线观看| 亚洲人成在线观看| 国产精品毛片a∨一区二区三区| 欧美与黑人午夜性猛交久久久| 久久aⅴ国产紧身牛仔裤| 亚洲福利视频专区| 一区二区三区国产在线观看| 国产一区二区三区四区hd| 欧美www在线| 国产精品久久久久久久浪潮网站| 久久大逼视频| 欧美激情四色 | 亚洲国产精品嫩草影院| 亚洲精品人人| 黑人巨大精品欧美一区二区小视频 | 另类图片国产| 欧美午夜电影在线| 男女激情久久| 国产精品亚洲аv天堂网| 免费成人在线观看视频| 欧美午夜精品久久久| 蜜桃伊人久久| 国产精品一区二区三区四区| 亚洲福利视频一区二区| 国产日韩精品久久久| 91久久精品国产91久久性色tv | 国产精品高潮在线| 欧美大尺度在线| 国产美女精品| av成人免费在线观看| 一区在线影院| 午夜精品三级视频福利| 亚洲精品在线电影| 久久久久九九九| 欧美在线视频一区二区| 欧美日韩国语| 亚洲经典自拍| 亚洲国产精品成人| 欧美中文在线视频| 性18欧美另类| 欧美午夜欧美| 一区二区三欧美| 亚洲麻豆国产自偷在线| 久久一区中文字幕| 狼人社综合社区| 国产一区二区久久精品| 亚洲男人的天堂在线观看| 亚洲一区国产一区| 欧美精品一区在线| 亚洲精品之草原avav久久| 亚洲精品五月天| 欧美精品一区三区| 亚洲欧洲一区| 一本色道久久综合亚洲二区三区| 麻豆精品传媒视频| 欧美福利视频| 亚洲美女精品一区| 欧美日本高清| 亚洲社区在线观看| 欧美一区二区三区久久精品茉莉花| 国产精品v欧美精品v日韩精品| 一本久道久久久| 羞羞答答国产精品www一本| 国产精品久久久爽爽爽麻豆色哟哟 | 一本色道久久99精品综合 | 欧美fxxxxxx另类| 亚洲大胆av| 亚洲另类视频| 欧美特黄视频| 欧美一区免费视频| 欧美肥婆bbw| 一区二区三区久久| 国产欧美精品在线| 久久人人爽人人爽爽久久| 欧美激情成人在线视频| 日韩亚洲国产欧美| 国产精品一区二区三区成人| 欧美一区国产二区| 亚洲国产欧美精品| 亚洲伊人一本大道中文字幕| 国产亚洲福利社区一区| 狂野欧美性猛交xxxx巴西| 亚洲三级免费电影| 欧美综合国产| 亚洲人成人一区二区在线观看| 欧美视频一区二区三区四区| 先锋影音国产精品| 91久久精品国产91性色| 午夜精品久久久久久久99樱桃| 国产主播精品在线| 欧美久久精品午夜青青大伊人| 亚洲一区二区高清| 欧美激情精品久久久久久变态| 亚洲一区二区黄| 在线精品视频免费观看| 欧美亚男人的天堂| 另类激情亚洲| 亚洲欧美日韩专区| 亚洲精品女人| 性欧美video另类hd性玩具| 在线电影国产精品| 国产精品免费一区豆花| 欧美成人精精品一区二区频| 午夜天堂精品久久久久| 亚洲国产精品嫩草影院| 久久久久这里只有精品| 亚洲一区二区三区四区五区黄| 亚洲动漫精品| 国产在线欧美| 国产精品一二三四| 欧美久久一级| 欧美xxx在线观看| 久久精品九九| 香蕉久久夜色精品国产| 一本色道久久综合狠狠躁篇怎么玩 | 欧美日韩www| 美女尤物久久精品| 久久精品国产一区二区三| 亚洲欧洲一区二区天堂久久 | 国产精品99久久久久久久久| 亚洲国产片色| 亚洲第一福利在线观看| 国产色婷婷国产综合在线理论片a| 欧美日韩伦理在线| 欧美金8天国| 欧美国产激情二区三区| 免费日韩视频| 欧美gay视频激情| 欧美不卡视频| 欧美成人首页| 欧美精品www| 欧美理论在线| 欧美日韩精品免费观看视频完整| 欧美成人综合| 欧美精品 国产精品| 欧美成人亚洲成人| 欧美激情第一页xxx| 欧美刺激午夜性久久久久久久| 久久综合网色—综合色88| 久久久久久香蕉网| 老鸭窝毛片一区二区三区| 久久深夜福利免费观看| 老司机午夜精品视频| 欧美ed2k| 欧美日韩亚洲网| 国产精品一二| 精品9999| 亚洲精品午夜精品| 亚洲视频观看| 性欧美办公室18xxxxhd| 久久乐国产精品| 亚洲观看高清完整版在线观看| 亚洲欧洲日产国产网站| 中文在线资源观看网站视频免费不卡| 夜夜嗨av一区二区三区网页| 亚洲一区二区在线视频| 久久国产乱子精品免费女| 美女91精品| 国产精品精品视频| 狠久久av成人天堂| 亚洲最新视频在线| 欧美一级久久| 欧美国产视频在线观看| 亚洲精品一区在线| 香蕉av777xxx色综合一区| 欧美18av| 国产精品永久| 亚洲人成网站色ww在线| 亚洲男人av电影| 欧美jjzz| 亚洲专区一区二区三区| 麻豆成人小视频| 国产精品一区二区三区免费观看| 在线观看视频亚洲| 午夜精品久久久久久久久久久| 美女精品视频一区| 亚洲深夜激情| 欧美成人首页| 国产一区激情| 亚洲视频久久| 欧美激情中文字幕一区二区| 亚洲一区免费网站| 欧美激情欧美激情在线五月| 国产欧美日韩激情| 一区二区三区日韩精品视频| 久久中文欧美| 亚洲一区免费在线观看| 欧美美女bbbb| 亚洲国产欧美一区二区三区丁香婷| 亚洲欧美在线网| a4yy欧美一区二区三区| 欧美.日韩.国产.一区.二区| 一区二区三区无毛|