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

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>
            欧美高清日韩| 欧美国产日本在线| 国产人成精品一区二区三| 亚洲一区视频在线| 亚洲永久免费| 国产主播一区二区三区| 久热精品在线| 免费看亚洲片| 亚洲一区二区不卡免费| 亚洲尤物视频网| 尤物网精品视频| 亚洲国产小视频| 欧美日韩在线亚洲一区蜜芽| 亚洲免费在线播放| 久久不见久久见免费视频1| 亚洲电影在线看| av成人免费观看| 激情成人综合网| 亚洲理论在线观看| 国产一区二区日韩精品欧美精品| 玖玖精品视频| 欧美日精品一区视频| 欧美专区日韩专区| 欧美大片在线看免费观看| 午夜精品久久久久久久99热浪潮| 久久av老司机精品网站导航| 亚洲品质自拍| 欧美在线观看视频| 中国日韩欧美久久久久久久久| 午夜精品一区二区三区电影天堂| 亚洲激情不卡| 欧美一区二区日韩| 在线视频欧美一区| 久久久久久一区二区三区| 一区二区三区精品视频在线观看| 午夜在线a亚洲v天堂网2018| 99精品欧美一区二区三区| 欧美在线免费视频| 午夜电影亚洲| 欧美激情第二页| 鲁鲁狠狠狠7777一区二区| 国产精品美女999| 亚洲精品中文字幕在线| 一区免费在线| 欧美在线三区| 小黄鸭精品aⅴ导航网站入口| 欧美激情视频免费观看| 免费看的黄色欧美网站| 国产午夜精品一区二区三区欧美| 99国产精品一区| 日韩视频免费大全中文字幕| 久久免费视频在线观看| 久久久久久久久伊人| 国产精品久久久久久av福利软件| 亚洲国产毛片完整版 | 毛片av中文字幕一区二区| 欧美影院成人| 国产精品亚洲视频| 99国产精品一区| 99re6这里只有精品| 美女精品网站| 亚洲福利视频网站| 亚洲高清资源综合久久精品| 久久成人精品电影| 久久精品国产999大香线蕉| 国产精品亚洲欧美| 香港成人在线视频| 久久久久久久久久久一区| 国产亚洲视频在线观看| 性欧美xxxx大乳国产app| 久久精品中文字幕一区| 国产亚洲欧美激情| 久久久久久网站| 欧美 日韩 国产在线| 亚洲人成精品久久久久| 欧美大胆人体视频| 日韩天堂在线观看| 午夜精品久久99蜜桃的功能介绍| 国产精品二区在线| 亚洲一区欧美一区| 久久久亚洲欧洲日产国码αv | 国产精品成人一区二区艾草| 亚洲桃花岛网站| 久久激情婷婷| 最新精品在线| 欧美午夜精品久久久久久超碰| 一本色道88久久加勒比精品| 欧美一区二区成人| 亚洲福利一区| 欧美激情中文不卡| 亚洲一区免费网站| 久久综合色婷婷| 一区二区三区www| 国产日韩欧美在线观看| 麻豆精品精华液| 夜夜爽av福利精品导航| 久久久青草青青国产亚洲免观| 最新亚洲一区| 国产精品人成在线观看免费 | 亚洲风情在线资源站| 亚洲网站啪啪| 国户精品久久久久久久久久久不卡| 鲁大师影院一区二区三区| 在线视频欧美日韩精品| 久久久五月婷婷| 在线一区二区三区做爰视频网站| 国产欧美精品日韩精品| 欧美—级a级欧美特级ar全黄| 亚洲一区日韩在线| 亚洲国产精品一区二区第四页av| 香蕉久久a毛片| 亚洲精品欧洲| 激情文学综合丁香| 国产精品男人爽免费视频1 | 中文精品在线| 亚洲电影下载| 久久天天躁狠狠躁夜夜av| 亚洲线精品一区二区三区八戒| 影音先锋日韩资源| 国产欧美在线播放| 欧美日韩人人澡狠狠躁视频| 久久激情综合| 亚洲一区二区三区在线观看视频| 亚洲成人在线视频网站| 久久久五月婷婷| 欧美一区二区三区成人| 亚洲网站视频福利| 亚洲精选久久| 亚洲精品视频在线看| 影音先锋亚洲视频| 国内精品伊人久久久久av影院 | 国内久久视频| 国产人成精品一区二区三| 国产精品yjizz| 欧美日本韩国一区| 欧美精品久久久久久| 欧美成人一区在线| 麻豆国产va免费精品高清在线| 久久精彩免费视频| 欧美中文字幕| 久久久久久久波多野高潮日日| 亚洲欧美日韩国产综合在线 | 亚洲精品国产精品国自产观看浪潮| 久久理论片午夜琪琪电影网| 欧美亚洲网站| 欧美日韩精品免费在线观看视频| 午夜免费电影一区在线观看 | 国产日韩欧美不卡| 国产日产欧产精品推荐色 | 91久久精品美女| 亚洲国产精品嫩草影院| 亚洲国产精品视频| 亚洲精品视频二区| av成人免费观看| 亚洲午夜精品在线| 香蕉久久夜色精品| 久久九九热免费视频| 久久天天躁狠狠躁夜夜av| 老司机午夜精品视频在线观看| 蜜臀av在线播放一区二区三区 | 午夜视频一区二区| 久久久精品国产免大香伊| 猛干欧美女孩| 欧美四级在线| 国产亚洲va综合人人澡精品| 一区精品久久| 一区二区三区导航| 欧美在线电影| 亚洲第一黄色网| 亚洲午夜精品一区二区| 久久精品国产第一区二区三区最新章节| 久久久999精品免费| 美乳少妇欧美精品| 国产精品理论片| 在线观看日产精品| 亚洲一卡久久| 另类成人小视频在线| 亚洲三级影片| 久久精品国产亚洲a| 欧美日本一区| 国内精品亚洲| 亚洲一区久久久| 欧美福利视频| 亚洲欧美精品伊人久久| 欧美国产国产综合| 国产亚洲综合性久久久影院| 日韩一级大片在线| 久久久激情视频| 一本色道久久综合狠狠躁篇怎么玩 | 久久国产欧美日韩精品| 欧美精选午夜久久久乱码6080| 国产日韩av一区二区| 日韩视频―中文字幕| 久久综合中文字幕| 亚洲淫性视频| 欧美日韩视频一区二区| 亚洲国产精品激情在线观看| 欧美一级欧美一级在线播放| 91久久亚洲| 久久综合999|