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

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>
            在线精品福利| 国产午夜精品视频| 亚洲卡通欧美制服中文| 欧美 日韩 国产一区二区在线视频| 亚洲欧美日韩在线| 国内久久婷婷综合| 欧美福利小视频| 欧美成人一区二区在线| 99精品黄色片免费大全| 中国女人久久久| 国产日韩一区二区三区| 老司机67194精品线观看| 免费亚洲一区二区| 亚洲一二三四久久| 欧美一区二区精美| 亚洲国产美国国产综合一区二区| 最新国产の精品合集bt伙计| 欧美日韩一区二区在线| 久久国产综合精品| 久久综合给合| 亚洲尤物视频网| 久久精品国产99国产精品澳门| 亚洲青涩在线| 亚洲欧美日本在线| 亚洲韩国日本中文字幕| 亚洲一本大道在线| 好吊妞这里只有精品| 亚洲精品亚洲人成人网| 国产日本欧美一区二区三区| 欧美国产精品| 国产视频观看一区| 亚洲精品乱码久久久久久黑人| 国产精品美女午夜av| 亚洲成人在线视频网站| 国产精品婷婷| 亚洲精品乱码久久久久| 黄色免费成人| 亚洲影院色无极综合| 亚洲另类视频| 久久野战av| 欧美专区在线观看| 欧美日韩1080p| 免费成人黄色片| 国产精品一区二区三区久久| 亚洲人成在线观看| 1000部精品久久久久久久久| 亚洲免费中文字幕| 亚洲视频在线观看| 欧美国产日产韩国视频| 久久夜色精品一区| 国产精品一区二区三区久久| 亚洲精品久久视频| 亚洲破处大片| 免费亚洲电影在线观看| 免费精品99久久国产综合精品| 国产精品试看| 亚洲天堂免费在线观看视频| 一本大道久久a久久精品综合| 久久综合九色99| 久久久www成人免费毛片麻豆| 国产精品女人网站| 一区二区三区国产| 亚洲一区激情| 欧美三区不卡| 中文欧美字幕免费| 亚洲一区二区三区影院| 欧美日韩伦理在线免费| 亚洲精品少妇| 亚洲香蕉成视频在线观看| 欧美欧美全黄| 99日韩精品| 亚洲专区免费| 国产嫩草影院久久久久| 亚洲欧美日本视频在线观看| 久久激情视频| 激情国产一区二区| 麻豆精品传媒视频| 欧美三级欧美一级| 亚洲国产精品一区| 久热精品视频在线观看一区| 欧美理论电影在线播放| 亚洲人成亚洲人成在线观看图片| 亚洲精品人人| 欧美视频在线视频| 亚洲综合国产激情另类一区| 久久av最新网址| 国产专区欧美精品| 美女脱光内衣内裤视频久久影院| 亚洲茄子视频| 午夜激情一区| 悠悠资源网亚洲青| 欧美区在线观看| 亚洲一区久久久| 久久综合图片| 一本大道久久a久久精品综合| 国产精品国产自产拍高清av王其 | 久久精品亚洲热| 伊人成年综合电影网| 欧美日韩视频在线| 久久精品中文字幕一区二区三区| 亚洲韩国日本中文字幕| 小黄鸭视频精品导航| 亚洲激情啪啪| 国产农村妇女精品一二区| 美女脱光内衣内裤视频久久影院| 亚洲无毛电影| 欧美激情精品久久久久久免费印度| 中文日韩在线| 亚洲成在人线av| 国产精品久久一区二区三区| 另类激情亚洲| 亚洲一区亚洲二区| 亚洲人成免费| 久久久久国产精品一区二区| 亚洲电影第1页| 欧美日韩亚洲国产一区| 欧美一区二区三区在线观看| 亚洲精品永久免费精品| 久久精品二区| aa级大片欧美三级| 国产亚洲女人久久久久毛片| 一区二区日韩欧美| 亚洲激情偷拍| 久久精品国产精品| 妖精成人www高清在线观看| 国产精品亚洲аv天堂网| 欧美寡妇偷汉性猛交| 欧美一区二区播放| 国产一区二区三区不卡在线观看| 欧美成人中文字幕在线| 久久不射2019中文字幕| 欧美黄色一区二区| 浪潮色综合久久天堂| 亚洲欧美日韩国产一区二区| 亚洲欧洲中文日韩久久av乱码| 国产精品美女视频网站| 久久精品亚洲精品国产欧美kt∨| 亚洲欧美日韩一区二区三区在线观看 | 亚洲一线二线三线久久久| 久久久av毛片精品| 午夜精品福利视频| 在线视频一区观看| 亚洲欧洲久久| 激情自拍一区| 国产欧美不卡| 国产精品精品视频| 欧美日本精品一区二区三区| 老**午夜毛片一区二区三区| 久久精品首页| 亚洲伊人网站| 亚洲女同同性videoxma| 亚洲色图在线视频| 一区二区三区av| 亚洲精品一区二区三区婷婷月 | 久久不射2019中文字幕| 亚洲欧美国内爽妇网| 亚洲视频中文字幕| 一区二区三区四区五区视频| 国产亚洲精品久久久久动| 狠色狠色综合久久| 尤物yw午夜国产精品视频明星| 国产一区二三区| 狠狠色综合日日| 亚洲国产精品999| 亚洲精品午夜| 国产精品99久久久久久宅男| 亚洲精品一区二区三区樱花 | 宅男噜噜噜66一区二区66| 一区二区三区欧美日韩| 亚洲午夜久久久久久久久电影院| 亚洲色图在线视频| 欧美一区二区三区日韩视频| 久久五月婷婷丁香社区| 欧美成人一区二区三区片免费| 欧美激情一区在线观看| 亚洲精品视频在线| 欧美一二三区在线观看| 麻豆成人小视频| 欧美日韩久久精品| 国产精品色午夜在线观看| 免费毛片一区二区三区久久久| 欧美午夜一区| 国产情侣久久| 最新成人在线| 亚洲一区久久久| 欧美一区二区私人影院日本 | 国产视频在线观看一区二区| 亚洲精品日韩综合观看成人91| 亚洲一区二区三区精品在线 | 狠狠色丁香婷婷综合久久片| 一区二区日韩精品| 久久久999精品免费| 欧美第一黄色网| 亚洲一区日韩在线| 亚洲主播在线| 欧美日韩国产高清| 国产一区欧美| 亚洲综合色丁香婷婷六月图片| 久久久久久久久久久成人| 1024国产精品|