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

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 閱讀(388) 評論(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| 亚洲精品欧美日韩| 国产视频在线观看一区二区三区| 久久久综合网站| 欧美精品一区三区| 久久精品国产精品亚洲| 女人天堂亚洲aⅴ在线观看| 亚洲午夜精品17c| 久久久久久久综合狠狠综合| 日韩一区二区精品| 欧美在线短视频| 一本一本久久a久久精品综合麻豆| 亚洲一区国产精品| 亚洲乱码精品一二三四区日韩在线 | 欧美色综合天天久久综合精品| 亚洲综合欧美| 嫩模写真一区二区三区三州| 亚洲一二三区在线观看| 久久五月激情| 欧美亚洲免费| 欧美日韩国产成人在线| 久久综合伊人77777| 国产精品护士白丝一区av| 免费日韩精品中文字幕视频在线| 国产精品高清网站| 亚洲国产精品一区制服丝袜| 国产日韩欧美成人| 一区二区激情| 一区二区三区国产精华| 麻豆av一区二区三区久久| 久久国产日韩欧美| 国产精品男女猛烈高潮激情 | 免播放器亚洲一区| 国产精品专区h在线观看| 亚洲精品综合在线| 亚洲国产二区| 久久久久久久久岛国免费| 午夜精品久久久久久久99水蜜桃 | 91久久精品日日躁夜夜躁欧美| 午夜精品久久久99热福利| 亚洲已满18点击进入久久| 欧美国产亚洲精品久久久8v| 麻豆精品在线视频| 国产一区二区在线观看免费播放 | 亚洲二区精品| 亚洲日本激情| 欧美激情一区二区三区蜜桃视频| 欧美 日韩 国产 一区| 精品福利av| 久久久久久伊人| 老司机成人网| 亚洲第一色中文字幕| 久久精品亚洲精品| 久久综合色播五月| 在线观看日产精品| 老司机午夜精品| 亚洲国产精品视频一区| 亚洲区欧美区| 欧美午夜精品| 亚洲男人第一av网站| 久久激情综合网| 黄色成人片子| 欧美激情亚洲视频| 在线综合亚洲| 久久精品在这里| 亚洲大片一区二区三区| 欧美成人精品激情在线观看| 亚洲国产日韩欧美在线图片| aa国产精品| 国产欧美 在线欧美| 欧美资源在线观看| 亚洲大片免费看| 亚洲一级片在线看| 国产午夜精品视频| 老司机精品视频一区二区三区| 欧美激情一二三区| 亚洲一区在线播放| 极品少妇一区二区三区| 欧美激情视频一区二区三区免费| 亚洲深爱激情| 毛片av中文字幕一区二区| 亚洲精选中文字幕| 国产欧美日韩一区二区三区在线| 久久精品动漫| 日韩午夜黄色| 另类激情亚洲| 亚洲欧美日韩高清| 亚洲韩国一区二区三区| 国产精品久久久久久久浪潮网站 | 久久久久久亚洲精品杨幂换脸| 91久久在线播放| 久久久久www| 亚洲图片在区色| 亚洲国产导航| 国产偷自视频区视频一区二区| 欧美激情综合网| 久久久久久久久伊人| 亚洲午夜精品17c| 亚洲国产日韩一区| 久久一区免费| 欧美伊人精品成人久久综合97| 亚洲欧洲三级| 有坂深雪在线一区| 国产精品亚洲аv天堂网| 欧美精品日韩| 美女999久久久精品视频| 亚洲欧美日韩专区| 亚洲视频欧洲视频| 亚洲精品乱码久久久久久黑人 | 一区二区免费在线播放| 亚洲国产成人高清精品| 久久中文字幕一区二区三区| 亚洲欧美在线一区二区| 亚洲一区二区三区在线播放| 亚洲日韩视频| 亚洲国产一二三| 亚洲第一精品在线| 在线高清一区| 一区视频在线| 黄色亚洲网站| 一区在线免费观看| 在线电影一区| 亚洲国产欧美在线人成| 一区久久精品| 亚洲国产精品久久久久| 亚洲高清自拍| 亚洲欧洲日本专区| 亚洲另类春色国产| 亚洲免费福利视频| 一本一道久久综合狠狠老精东影业| 亚洲高清网站| 99精品视频一区二区三区| 亚洲免费观看高清在线观看| 亚洲美女色禁图| 一区二区三欧美| 亚洲免费中文字幕| 欧美伊人久久| 蜜桃伊人久久| 91久久精品国产91性色| 亚洲精品中文字幕有码专区| aⅴ色国产欧美| 亚洲一区免费| 久久免费精品日本久久中文字幕| 麻豆成人在线| 欧美日韩国产在线看| 国产精品久久影院| 国语自产偷拍精品视频偷 | 国产精品成人一区二区| 欧美与欧洲交xxxx免费观看| 极品中文字幕一区| 国产一区二区久久精品| 欧美日韩精品综合| 国产亚洲一区二区三区在线播放| 国产日韩欧美视频在线| 国产自产高清不卡| 亚洲精品一区二区三区四区高清| 一本在线高清不卡dvd| 欧美在线视频观看免费网站| 久久综合给合久久狠狠色| 亚洲国产老妈| 亚洲在线观看免费视频| 久久久综合香蕉尹人综合网| 欧美伦理a级免费电影| 国产日韩一区| 日韩视频一区二区三区在线播放免费观看 | 亚洲电影成人| 午夜亚洲激情| 欧美电影在线免费观看网站| 国产精品久久久久高潮| 在线看欧美日韩| 亚洲女优在线| 亚洲国产精品国自产拍av秋霞| 亚洲一二三区视频在线观看| 久久色中文字幕| 国产精品亚洲综合色区韩国| 亚洲精品一区二区三区av| 欧美怡红院视频| 亚洲精品永久免费精品| 久久欧美中文字幕| 国产乱码精品一区二区三区av| 亚洲人成网站999久久久综合| 久久狠狠亚洲综合| 日韩一级视频免费观看在线| 另类综合日韩欧美亚洲| 国产视频自拍一区| 亚洲综合色噜噜狠狠| 亚洲国产日韩在线| 老鸭窝亚洲一区二区三区| 国产亚洲欧美一区二区三区|