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

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 閱讀(397) 評(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>
            欧美日韩在线观看一区二区三区 | 一区免费观看| 欧美怡红院视频| 亚洲影院在线观看| 国产情侣一区| 久久视频这里只有精品| 久久久久国产一区二区三区四区| 国内精品久久久久久久果冻传媒| 久久深夜福利| 久久天天躁夜夜躁狠狠躁2022 | 欧美人牲a欧美精品| 99re6热在线精品视频播放速度| 亚洲激情六月丁香| 国产精品国产三级国产普通话三级| 亚洲深夜福利| 欧美在线一二三四区| 亚洲日本一区二区| 欧美日韩一区免费| 999在线观看精品免费不卡网站| 亚洲第一区色| 欧美日韩精品综合在线| 午夜日韩视频| 久久久国产精品一区| 日韩天堂av| 亚洲欧美一区二区三区极速播放 | 欧美成人国产一区二区| 一区二区三区日韩欧美精品| 亚洲欧美日韩国产| 亚洲人成人77777线观看| 99日韩精品| 亚洲高清免费视频| 中文日韩在线视频| 亚洲成色www8888| 亚洲天堂男人| 亚洲精品九九| 欧美一区不卡| 一区二区三区精品久久久| 欧美在线观看www| 一区二区三区精品视频| 久久久久久9| 欧美一区成人| 欧美日韩成人一区二区| 免播放器亚洲一区| 国产精品一区二区久久精品| 亚洲国产成人精品女人久久久| 国产美女精品免费电影| 亚洲美女电影在线| 亚洲国产日日夜夜| 欧美专区在线| 久久精品国产一区二区电影| 欧美视频免费在线观看| 免费在线欧美视频| 国产亚洲aⅴaaaaaa毛片| 99伊人成综合| 99在线热播精品免费99热| 久久亚洲国产精品日日av夜夜| 午夜精品理论片| 欧美色欧美亚洲高清在线视频| 欧美激情在线观看| 在线精品国产成人综合| 久久se精品一区精品二区| 午夜精品久久久久久久99樱桃 | 欧美精品久久久久a| 欧美freesex8一10精品| 影音先锋久久| 久久精品五月婷婷| 久久免费国产精品| 伊人成综合网伊人222| 久久成人久久爱| 久久久午夜视频| 一色屋精品视频在线看| 国产一区二区欧美| 美女视频黄 久久| 黑人巨大精品欧美一区二区| 亚洲欧美综合另类中字| 性欧美1819sex性高清| 国产精品白丝av嫩草影院 | 一区二区精品国产| 欧美日韩亚洲一区二区三区在线| 最新日韩av| 日韩小视频在线观看| 欧美日韩三区| 99精品欧美一区二区三区| 亚洲综合首页| 国产精品自拍在线| 欧美亚洲尤物久久| 欧美v日韩v国产v| 日韩天堂av| 国产精品日韩专区| 久久久国产一区二区| 欧美高清不卡| 亚洲视频在线观看免费| 国产欧美一区二区三区在线看蜜臀 | 亚洲精品久久嫩草网站秘色 | 在线一区亚洲| 久久av在线看| 亚洲高清av| 欧美视频亚洲视频| 久久se精品一区二区| 欧美国产视频一区二区| 亚洲一区亚洲二区| 国内精品久久久久久久影视蜜臀 | 久久人人超碰| 日韩午夜免费| 欧美一级视频免费在线观看| 一区在线免费| 欧美午夜欧美| 久久久青草青青国产亚洲免观| 91久久精品日日躁夜夜躁欧美| 午夜精品美女自拍福到在线 | 欧美涩涩网站| 欧美自拍偷拍午夜视频| 亚洲国产裸拍裸体视频在线观看乱了| 亚洲伊人伊色伊影伊综合网| 国产私拍一区| 欧美午夜精品| 美女91精品| 亚洲综合成人婷婷小说| 亚洲激情中文1区| 久久久久久久尹人综合网亚洲 | 国产色婷婷国产综合在线理论片a| 久久精品视频在线| 中日韩在线视频| 亚洲高清不卡在线观看| 久久久视频精品| 亚洲欧美日本另类| 日韩视频一区二区| 在线观看欧美一区| 国产欧美在线视频| 欧美香蕉视频| 欧美日韩精品在线播放| 免费成人你懂的| 久久欧美中文字幕| 久久精品一区二区三区中文字幕| 亚洲美女啪啪| 亚洲人成网站色ww在线| 免费观看一区| 美女视频黄免费的久久| 久久免费精品视频| 久久久青草婷婷精品综合日韩| 性做久久久久久久免费看| 亚洲专区免费| 亚洲一区二区精品在线观看| 99精品视频免费观看视频| 亚洲啪啪91| 亚洲精品国产拍免费91在线| 亚洲经典视频在线观看| 亚洲国产裸拍裸体视频在线观看乱了中文 | 久久久国产亚洲精品| 欧美中文在线视频| 久久岛国电影| 久久国产精品99精品国产| 欧美资源在线| 久久婷婷丁香| 欧美不卡视频一区发布| 欧美另类69精品久久久久9999| 嫩草伊人久久精品少妇av杨幂| 看欧美日韩国产| 欧美xx69| 欧美性大战久久久久久久| 国产精品久久久久aaaa樱花 | 久久久中精品2020中文| 久久资源在线| 欧美 日韩 国产一区二区在线视频 | 99精品99| 欧美亚洲一区三区| 久久一区二区三区av| 欧美激情精品久久久久久黑人 | 国产精品一区免费在线观看| 国产欧美视频一区二区| 在线不卡免费欧美| 艳妇臀荡乳欲伦亚洲一区| 亚洲综合视频一区| 久久视频在线免费观看| 亚洲国产另类久久精品| 正在播放欧美视频| 久久精品中文字幕一区| 欧美另类变人与禽xxxxx| 国产欧美日本| 亚洲国产免费看| 香蕉久久久久久久av网站| 欧美/亚洲一区| 在线视频日本亚洲性| 久久久久一区| 国产精品卡一卡二卡三| 1024欧美极品| 香蕉久久一区二区不卡无毒影院| 六十路精品视频| 亚洲一二三区视频在线观看| 开元免费观看欧美电视剧网站| 国产精品www.| 亚洲国产精品第一区二区三区| 亚洲香蕉在线观看| 欧美成年人视频网站欧美| 亚洲视频视频在线| 欧美波霸影院| 国内外成人在线视频| 正在播放日韩| 欧美国产日本在线| 久久精品99无色码中文字幕|