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

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>
            激情一区二区三区| 久热国产精品| 蜜桃伊人久久| 久久国产精品毛片| 欧美午夜精品久久久久久人妖 | 欧美多人爱爱视频网站| 欧美亚洲一级| 欧美日韩另类一区| 亚洲国产视频a| 激情欧美一区二区三区| 亚洲一区视频在线| 亚洲女人小视频在线观看| 欧美韩国日本综合| 欧美激情一区二区三区| 在线精品视频一区二区| 久久精品夜夜夜夜久久| 欧美一级播放| 国产精品专区第二| 香蕉成人啪国产精品视频综合网| 亚洲影视综合| 国产精品女人久久久久久| 在线视频一区二区| 亚洲男人第一网站| 国产乱码精品一区二区三区av| 正在播放欧美视频| 亚洲欧美日韩一区在线观看| 国产精品久久久久影院亚瑟| 99视频超级精品| 亚洲欧美精品| 国产香蕉久久精品综合网| 香蕉av777xxx色综合一区| 久久久xxx| 亚洲第一黄网| 欧美精品日韩| 一区二区三区高清在线观看| 亚洲欧美制服另类日韩| 国产精品丝袜xxxxxxx| 欧美一区二区三区啪啪| 久久综合中文| 日韩视频国产视频| 国产精品a级| 欧美一区二区三区婷婷月色 | 亚洲欧美偷拍卡通变态| 久久精品国产精品| 亚洲电影在线| 欧美日韩国产系列| 亚洲专区免费| 欧美电影打屁股sp| 亚洲一区二区三区免费视频| 国产精品日韩精品| 久久亚洲精品中文字幕冲田杏梨 | 欧美一区网站| 欧美成人精品1314www| 一个人看的www久久| 国产精品久久久久aaaa| 久久精品国产久精国产思思| 欧美国产一区二区| 亚洲欧美激情一区二区| 亚洲成人在线免费| 欧美日韩国产免费观看| 欧美一二三视频| 91久久精品www人人做人人爽| 亚洲一区在线直播| 亚洲电影下载| 国产精品日韩精品欧美精品| 久久免费视频网站| 亚洲一区二区综合| 欧美激情国产日韩| 久久精品三级| 亚洲一区二区四区| 亚洲激情欧美激情| 国产在线视频欧美一区二区三区| 欧美顶级大胆免费视频| 欧美一区中文字幕| 亚洲视频www| 亚洲国产精品一区二区久| 久久激情网站| 亚洲一区二区三区在线| 亚洲国产精品久久人人爱蜜臀| 欧美三区美女| 欧美国产精品久久| 久久久噜噜噜久久人人看| 亚洲一区二区3| 亚洲精品视频在线播放| 猛男gaygay欧美视频| 欧美在线视频a| 一区二区三区国产在线观看| 亚洲第一天堂av| 国产自产2019最新不卡| 国产精品毛片a∨一区二区三区| 欧美黄色aa电影| 在线视频观看日韩| 国产亚洲精品aa午夜观看| 欧美午夜不卡视频| 欧美日韩亚洲免费| 欧美精品久久99| 欧美成人蜜桃| 女同一区二区| 免费日韩av片| 男女精品网站| 欧美风情在线| 欧美激情bt| 欧美日韩国产成人在线91| 欧美成人中文字幕在线| 蜜臀久久99精品久久久画质超高清 | 欧美日韩免费观看一区=区三区| 久久综合久久美利坚合众国| 久久成人av少妇免费| 欧美一站二站| 久久精品免费观看| 久久久久久久一区二区三区| 久久精品视频播放| 久久精品日韩一区二区三区| 久久精品国产免费看久久精品| 欧美一级专区| 久久久久久久性| 蜜桃av综合| 欧美精品大片| 国产精品久久久久久五月尺| 国产精品免费网站在线观看| 国产麻豆日韩欧美久久| 国内精品视频在线播放| 在线精品一区二区| 99国产精品视频免费观看一公开| 99国产精品视频免费观看| 亚洲一区二区综合| 久久成人免费电影| 欧美高清视频在线播放| 91久久嫩草影院一区二区| 亚洲毛片在线| 欧美亚洲免费电影| 久久一区二区三区国产精品 | 午夜国产精品视频免费体验区| 午夜欧美不卡精品aaaaa| 欧美亚洲综合网| 另类春色校园亚洲| 91久久香蕉国产日韩欧美9色| 99综合精品| 欧美在线免费观看| 欧美成人影音| 国产精品嫩草99a| 亚洲国产成人精品久久| 中文在线资源观看网站视频免费不卡| 午夜在线观看免费一区| 免费观看成人www动漫视频| 亚洲日韩欧美视频| 亚洲在线一区二区三区| 久久在线免费观看视频| 国产精品video| 亚洲国产岛国毛片在线| 亚洲一区成人| 亚洲第一精品久久忘忧草社区| 亚洲天堂男人| 欧美+日本+国产+在线a∨观看| 久久爱www| 亚洲国产经典视频| 欧美亚洲一区| 欧美伦理一区二区| 精品999久久久| 亚洲女性喷水在线观看一区| 欧美二区乱c少妇| 欧美一区二区成人6969| 欧美日本亚洲韩国国产| 激情久久久久久久| 午夜日韩在线| 亚洲免费成人av电影| 久久只精品国产| 国产一区二区主播在线| 一区二区三区国产在线| 欧美国产一区二区在线观看| 性欧美超级视频| 国产精品国产a级| 一区二区三区久久精品| 欧美国产日产韩国视频| 欧美伊人久久| 国产欧美一区二区三区在线老狼| 亚洲美女黄色| 你懂的亚洲视频| 久久精品国产视频| 国产日韩久久| 久久精品视频一| 午夜精品一区二区三区电影天堂| 欧美日韩精品在线| 亚洲精品久久久久久久久久久久| 老司机精品视频网站| 午夜精品一区二区在线观看 | 国产精品超碰97尤物18| 亚洲精品一二| 最近中文字幕mv在线一区二区三区四区| 欧美一级久久久久久久大片| 国产精品人人做人人爽| 亚洲欧美视频一区二区三区| 99热免费精品| 欧美视频在线免费| 亚洲在线中文字幕| 亚洲亚洲精品在线观看| 国产嫩草影院久久久久| 久久精品99久久香蕉国产色戒| 亚洲欧美日韩精品久久亚洲区| 国产欧美一级|