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

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 閱讀(395) 評論(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>
            欧美成ee人免费视频| 蜜桃视频一区| 国产偷国产偷精品高清尤物| 亚洲专区免费| 亚洲尤物视频在线| 国产亚洲精品aa午夜观看| 老司机久久99久久精品播放免费| 欧美在线一区二区| 亚洲人成在线播放网站岛国| 亚洲高清精品中出| 欧美日韩精品三区| 久久国产高清| 欧美高清视频一区二区三区在线观看| 亚洲精品视频在线观看免费| 99视频一区二区三区| 国产欧美日韩另类一区 | 国产美女精品免费电影| 久久免费高清视频| 欧美成人亚洲成人日韩成人| 亚洲一区二区3| 久久九九精品| 亚洲视频国产视频| 久久九九精品99国产精品| 亚洲精品欧美专区| 午夜在线不卡| 亚洲精品久久7777| 欧美一区二区日韩| 99国产精品久久久久老师 | 亚洲国产免费看| 国产精品每日更新在线播放网址| 久久综合色一综合色88| 欧美精品电影在线| 老司机精品视频网站| 国产精品久久久999| 欧美国产大片| 国产亚洲一区在线| 一区二区三区高清在线| 亚洲国产黄色| 欧美一级理论性理论a| 一区二区三区国产在线观看| 久久久不卡网国产精品一区| 亚洲桃花岛网站| 欧美高清免费| 欧美sm极限捆绑bd| 黄色精品在线看| 亚洲欧美成人一区二区三区| 一个色综合av| 男女av一区三区二区色多| 久久成人精品| 国产精品素人视频| 99精品国产在热久久下载| 亚洲欧洲一区二区三区在线观看| 欧美伊人精品成人久久综合97 | 国产精品视频久久| 99视频有精品| 一区二区三区视频在线| 欧美不卡一区| 欧美激情四色| 亚洲精品免费一二三区| 乱码第一页成人| 欧美成人精品高清在线播放| 国产专区精品视频| 欧美中文字幕视频| 久久久久久9| 国内精品久久久久伊人av| 亚洲欧美制服中文字幕| 欧美专区日韩视频| 国产三级精品三级| 欧美一二三区精品| 久久影院午夜片一区| 国语自产精品视频在线看8查询8 | 亚洲另类黄色| 一区二区三区四区五区在线 | 欧美制服丝袜| 老司机久久99久久精品播放免费| 狠狠噜噜久久| 免费在线看成人av| 亚洲精品1区2区| 一区二区成人精品| 国产精品久久久久999| 亚洲午夜未删减在线观看| 欧美一区二区视频在线观看| 国产一级揄自揄精品视频| 久久精品国产亚洲一区二区| 欧美国产日韩a欧美在线观看| 亚洲激情第一页| 欧美三区视频| 久久精品国产96久久久香蕉| 欧美顶级少妇做爰| 99国产精品久久久久久久成人热| 国产精品第三页| 久久精品日韩| 亚洲理论在线| 久久一区欧美| 99视频在线精品国自产拍免费观看| 欧美日韩精品在线播放| 亚洲欧美日韩网| 欧美风情在线观看| 亚洲欧洲av一区二区| 在线观看视频一区二区| 欧美精品一区二区蜜臀亚洲| 亚洲综合色在线| 欧美大片国产精品| 午夜精品视频在线观看| 亚洲国产成人久久综合一区| 欧美三级视频在线播放| 久久久久久久网站| 亚洲视频在线观看| 欧美激情1区2区| 久久爱www| 亚洲社区在线观看| 在线国产精品播放| 国产精品美女在线观看| 欧美不卡视频一区| 欧美一区二区三区在线| 亚洲精品在线一区二区| 久久亚洲视频| 欧美一区免费视频| 一区二区高清在线| 亚洲电影自拍| 国内外成人在线视频| 国产精品久久久久久久7电影| 欧美大成色www永久网站婷| 欧美亚洲视频在线看网址| 一本一本久久a久久精品牛牛影视| 蜜桃久久av一区| 久久久久久久一区二区三区| 亚洲一区区二区| 中文国产一区| 日韩写真视频在线观看| 亚洲国产精品成人一区二区| 国内精品国语自产拍在线观看| 欧美日韩一区二区三区高清| 欧美大片免费观看在线观看网站推荐| 欧美在线日韩| 性欧美1819sex性高清| 亚洲男人影院| 亚洲综合色激情五月| 亚洲一区二区三区在线播放| 亚洲精选视频在线| 日韩午夜在线视频| 一区二区三区精品久久久| 亚洲美女视频网| 99re视频这里只有精品| 亚洲精品美女91| 日韩一区二区精品在线观看| 亚洲日本无吗高清不卡| 亚洲日本欧美日韩高观看| 亚洲精品乱码久久久久久久久| 亚洲激情在线播放| 亚洲免费观看| 亚洲一区二区成人| 亚洲欧美激情视频| 欧美一区二区视频观看视频| 欧美一区二视频在线免费观看| 久久电影一区| 欧美成人三级在线| 欧美日韩在线视频一区二区| 国产精品a久久久久| 国产模特精品视频久久久久| 国产亚洲aⅴaaaaaa毛片| 黄色精品网站| 亚洲精品中文在线| 亚洲男同1069视频| 久久久人成影片一区二区三区观看| 久久视频一区二区| 亚洲激情欧美| 亚洲午夜久久久久久久久电影网| 欧美亚洲一级| 欧美不卡视频一区发布| 欧美性大战久久久久久久| 国产欧美一区二区三区视频| 伊人精品成人久久综合软件| 亚洲精品一区在线观看| 午夜亚洲激情| 欧美激情女人20p| 亚洲午夜日本在线观看| 久久久久久亚洲精品中文字幕| 欧美成人首页| 国产日韩欧美精品综合| 亚洲精品乱码| 久久精品国产亚洲aⅴ| 亚洲国产精品久久久久| 亚洲欧美日韩网| 欧美韩日精品| 黑人操亚洲美女惩罚| 亚洲伊人一本大道中文字幕| 久久免费观看视频| 中文精品视频| 免费美女久久99| 国产欧美日韩中文字幕在线| 亚洲精品免费在线| 久久夜色精品国产欧美乱极品| 亚洲美女视频在线观看| 久久亚洲私人国产精品va| 欧美性一二三区| 日韩写真视频在线观看| 噜噜爱69成人精品| 午夜视频在线观看一区二区三区 | 国产精品扒开腿爽爽爽视频|