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

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>
            午夜亚洲一区| 久久精品99国产精品酒店日本| 久久人人九九| 久久国产精品亚洲77777| 国产中文一区二区| 欧美在线观看视频| 久久精品在线观看| 亚洲第一页在线| 亚洲黄色免费电影| 欧美激情女人20p| 一区二区三区**美女毛片| 日韩亚洲欧美在线观看| 国产精品久久久久久久免费软件| 亚洲免费一级电影| 久久激情视频久久| 日韩视频―中文字幕| 亚洲美女精品久久| 国产欧美日韩视频一区二区三区| 久久久久久久国产| 欧美精品成人| 久久精品国产综合| 欧美国产日韩xxxxx| 午夜精品国产更新| 久久在线播放| 亚洲综合精品一区二区| 久久av最新网址| 一本大道久久精品懂色aⅴ| 在线亚洲一区观看| 亚洲高清中文字幕| 亚洲一区国产视频| 日韩亚洲综合在线| 久久激情综合网| 一区二区三区四区五区视频 | 在线观看视频日韩| 亚洲精品日韩一| 国内精品美女av在线播放| 亚洲精品视频一区二区三区| 国产一区二区三区四区hd| 亚洲国产欧美另类丝袜| 国产一区二区看久久| 亚洲三级电影在线观看| 好吊妞这里只有精品| 在线亚洲一区| 亚洲欧洲日本专区| 久久久久成人网| 欧美在线三区| 欧美午夜精品久久久久久久| 亚洲第一精品久久忘忧草社区| 国产深夜精品| 一区二区三区久久网| 亚洲人线精品午夜| 久久久久欧美精品| 久久精品二区| 国产视频一区在线观看| 亚洲天堂av综合网| 国产精品99久久久久久久久久久久| 久久亚洲精品中文字幕冲田杏梨| 性色av一区二区三区在线观看| 欧美精品日韩www.p站| 欧美电影资源| 在线观看视频欧美| 久久久无码精品亚洲日韩按摩| 性8sex亚洲区入口| 国产乱码精品一区二区三区av| 日韩视频在线一区二区| 亚洲免费电影在线| 欧美激情aaaa| 亚洲激情黄色| 99视频精品免费观看| 欧美精品一区二区蜜臀亚洲 | 欧美一级黄色录像| 国产精品视频1区| 亚洲午夜电影在线观看| 亚洲欧美激情精品一区二区| 欧美亚男人的天堂| 亚洲制服少妇| 久久黄色级2电影| 国内成人精品2018免费看| 欧美资源在线观看| 久久久久久亚洲精品杨幂换脸| 国产在线国偷精品产拍免费yy| 性感少妇一区| 蜜臀久久久99精品久久久久久| 久久久久久久久久码影片| 亚洲一区久久| 亚洲自拍都市欧美小说| 亚洲午夜91| 久久爱www.| 欧美特黄a级高清免费大片a级| 亚洲一区二区毛片| 亚洲国产欧美在线| 久久亚洲一区二区| 国产精品区免费视频| 国产日韩在线视频| 亚洲女人天堂av| 亚洲国产小视频在线观看| 一本色道久久加勒比精品| 亚洲视频1区| 欧美影院久久久| 蜜臀av一级做a爰片久久| 欧美激情按摩| 国产精品久在线观看| 日韩视频永久免费| 久久一区免费| 欧美插天视频在线播放| 国产一区日韩二区欧美三区| 国产一区二区三区四区在线观看| 一本久道久久综合婷婷鲸鱼| 亚洲欧美中文字幕| 国产情侣一区| 一区二区三区日韩在线观看| 久久精品在线视频| 国产精品v欧美精品v日韩| 日韩视频一区| 国产精品乱码久久久久久| 久久综合色婷婷| 最新日韩av| 久久大综合网| 一区二区三区色| 伊人久久婷婷| 国产精品一区视频| 欧美女主播在线| 美国十次了思思久久精品导航| 亚洲午夜精品久久| 亚洲激情国产精品| 久久人人看视频| 午夜免费日韩视频| 亚洲天堂偷拍| 亚洲美女电影在线| 1769国产精品| 国产真实久久| 国产偷国产偷亚洲高清97cao| 欧美日韩小视频| 欧美激情中文字幕一区二区 | 亚洲高清不卡在线| 国产一区二区三区在线免费观看| 欧美日韩大片| 欧美精品在线观看| 欧美成人免费播放| 久久夜色撩人精品| 久久久久国产精品一区三寸| 午夜精品国产更新| 亚洲午夜免费福利视频| 日韩一区二区高清| 亚洲作爱视频| 中文欧美在线视频| 亚洲视频在线观看| 亚洲制服av| 性欧美video另类hd性玩具| 日韩一级大片| 国产精品99久久久久久久久| 亚洲人成在线观看网站高清| 亚洲国产mv| 亚洲精品裸体| 亚洲性av在线| 亚洲欧美中文日韩在线| 羞羞漫画18久久大片| 久久国产精品久久久| 久久成人免费电影| 毛片基地黄久久久久久天堂| 欧美黄色片免费观看| 欧美精品一区二区在线播放| 欧美日韩性生活视频| 国产伦理一区| 樱桃国产成人精品视频| 亚洲精品麻豆| 亚洲一区二区在线| 久久精品国产精品| 欧美高清一区| 在线视频日韩| 欧美中文字幕在线播放| 蜜臀a∨国产成人精品| 欧美日韩亚洲一区在线观看| 国产日韩欧美中文在线播放| 亚洲电影天堂av| 在线视频你懂得一区| 久久精品久久综合| 亚洲激情社区| 亚洲欧美国产77777| 欧美 日韩 国产 一区| 欧美日韩在线观看视频| 国产一在线精品一区在线观看| 亚洲国产精品免费| 亚洲欧美日韩精品一区二区| 裸体丰满少妇做受久久99精品| 亚洲精品在线观| 欧美在线播放高清精品| 欧美精品乱码久久久久久按摩| 国产日韩高清一区二区三区在线| **性色生活片久久毛片| 亚洲欧美日韩系列| 亚洲国产高清一区二区三区| 亚洲欧美日韩国产综合| 美女精品在线观看| 国产人成一区二区三区影院 | 国产精品看片你懂得| 亚洲国产精品成人综合色在线婷婷| 亚洲在线观看免费视频| 欧美大片在线看| 欧美一区二区视频在线观看|