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

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 閱讀(392) 評論(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在线| 亚洲国产欧美久久| 亚洲国产精品毛片| 欧美日本国产一区| 亚洲一区二区在线免费观看视频 | 亚洲综合三区| 欧美一区二区性| 亚洲国产乱码最新视频| 亚洲精品欧美日韩专区| 欧美系列精品| 蜜乳av另类精品一区二区| 欧美高清视频免费观看| 亚洲一区二区高清| 久久精品99国产精品日本| 亚洲日韩中文字幕在线播放| 日韩亚洲欧美综合| 韩国一区二区三区在线观看| 欧美国产亚洲精品久久久8v| 欧美视频在线一区二区三区| 久久精品夜色噜噜亚洲aⅴ| 欧美+日本+国产+在线a∨观看| 99日韩精品| 久久免费的精品国产v∧| 亚洲视频在线视频| 卡通动漫国产精品| 欧美一区深夜视频| 欧美精品久久一区| 久久亚洲精品视频| 欧美图区在线视频| 欧美激情中文不卡| 国产手机视频一区二区| 亚洲精选在线| 亚洲电影天堂av| 午夜精彩国产免费不卡不顿大片| 亚洲精品视频一区| 久久成人免费电影| 欧美一区二区在线免费播放| 欧美激情视频给我| 美女在线一区二区| 国产日韩精品一区观看| 日韩视频在线观看| 亚洲精品国精品久久99热| 久久精品论坛| 久久99伊人| 国产精品视频xxx| 一本到高清视频免费精品| 亚洲电影网站| 久久久精品动漫| 欧美在线一二三四区| 欧美色中文字幕| 99视频精品免费观看| 亚洲精品免费在线播放| 美女日韩在线中文字幕| 久久亚洲私人国产精品va媚药| 国产精品久久久久免费a∨| 亚洲美女中出| 亚洲无毛电影| 欧美日韩一区二区三区四区五区| 亚洲激情校园春色| 日韩西西人体444www| 蜜臀久久99精品久久久久久9| 久久精品在线| 一区精品在线| 久久人人爽人人爽爽久久| 免费日韩av片| 亚洲国产精品久久久久婷婷老年| 久久综合影音| 亚洲精品国产品国语在线app| 亚洲精品国产拍免费91在线| 欧美激情va永久在线播放| 亚洲欧洲日韩女同| 亚洲校园激情| 国产欧美日韩中文字幕在线| 欧美中日韩免费视频| 免费观看亚洲视频大全| 亚洲乱码一区二区| 欧美视频观看一区| 午夜伦理片一区| 免费亚洲一区| 在线视频你懂得一区| 国产精品综合久久久| 久久久久久色| 亚洲国产成人91精品| 亚洲免费在线电影| 狠狠色香婷婷久久亚洲精品 | 亚洲精品视频在线看| 亚洲一二三区精品| 国产亚洲欧美激情| 欧美成年人网站| 亚洲一级在线观看| 你懂的视频一区二区| 一本一本久久a久久精品牛牛影视| 国产精品高精视频免费| 久久精品在线视频| 亚洲精品影院| 久久亚洲国产成人| 亚洲少妇一区| 国一区二区在线观看| 欧美日韩精品是欧美日韩精品| 亚洲欧美日韩综合aⅴ视频| 欧美a一区二区| 性色av一区二区三区红粉影视| 有坂深雪在线一区| 国产精品久久久久永久免费观看| 久久久久久综合| 夜夜爽www精品| 欧美成人午夜视频| 久久成人精品无人区| 日韩一本二本av| 精品999在线播放| 国产精品一区免费在线观看| 欧美二区乱c少妇| 久久精品中文字幕一区二区三区| 亚洲精品国产拍免费91在线| 久热精品视频| 欧美一站二站| 亚洲一级片在线看| 亚洲免费不卡| 亚洲国产一区二区视频| 国产一区二区在线观看免费播放 | 国产美女诱惑一区二区| 欧美激情一区二区三区在线视频 | 亚洲国产精品黑人久久久| 欧美在线视频网站| 亚洲一区二区三区午夜| 91久久国产自产拍夜夜嗨| 韩日视频一区| 国产亚洲一区二区三区在线观看| 国产精品高潮呻吟| 欧美日韩精品伦理作品在线免费观看| 老司机午夜精品视频在线观看| 欧美中文字幕在线观看| 亚洲制服少妇| 午夜精品久久久久久久白皮肤| 亚洲调教视频在线观看| 夜夜嗨av色综合久久久综合网 | 久久久97精品| 久久精品视频99| 久久久噜噜噜久噜久久| 久久人人爽国产| 久久综合一区二区三区| 牛人盗摄一区二区三区视频| 久久夜色精品国产欧美乱| 久久久久久久激情视频| 久久天天综合| 欧美v国产在线一区二区三区| 麻豆精品在线视频| 欧美激情在线狂野欧美精品| 亚洲国产第一| 9人人澡人人爽人人精品| 一区二区三区四区在线| 亚洲制服av| 欧美主播一区二区三区美女 久久精品人| 先锋影音久久| 久久性天堂网| 欧美日韩免费| 国产日韩精品一区二区三区在线| 国产亚洲一区二区在线观看| 在线观看亚洲视频| 日韩视频在线一区| 亚洲午夜日本在线观看| 久久不射网站| 欧美激情小视频| 一区二区三区不卡视频在线观看| 亚洲免费伊人电影在线观看av| 欧美在线免费看| 欧美激情亚洲激情| 国产精品毛片a∨一区二区三区|国 | 久久国产视频网站| 欧美国产第二页| 国产精品黄色| 亚洲第一黄色网| 亚洲砖区区免费| 欧美成年视频| 亚洲欧美中文日韩在线| 麻豆乱码国产一区二区三区| 欧美视频中文一区二区三区在线观看 | 有坂深雪在线一区| 亚洲一区二三| 欧美激情国产日韩| 亚洲专区一区二区三区| 欧美成人激情视频免费观看| 国产精品美女黄网| 亚洲精品三级| 久久亚洲综合色| 正在播放欧美视频| 欧美黄色网络| 影院欧美亚洲| 久久精品亚洲一区| 一区二区毛片| 欧美激情亚洲精品| 精品不卡视频| 久久久久久久综合狠狠综合| 一本大道久久a久久精品综合| 免费在线日韩av| 国产专区综合网| 午夜视频一区|