嚴以律己,寬以待人. 三思而后行. GMail/GTalk: yanglinbo#google.com; MSN/Email: tx7do#yahoo.com.cn; QQ: 3 0 3 3 9 6 9 2 0 .
class X { public: virtual ~X(); //析構函數 virtual void VirtualFunc(); //虛函數 inline int InlineFunc() { return m_iMember}; //內聯函數 void NormalFunc(); //普通成員函數 static void StaticFunc(); //靜態函數 private: int m_iMember; }; class XX: public X { public: XX(); virtual ~XX(); virtual void VirtualFunc(); private: String m_strName; int m_iMember2; };/FONT>
X obj; X* ptr = &obj; obj.StaticFunc(); ptr->StaticFunc(); X::StaticFunc();/FONT>
mangled_name_of_X_StaticFunc(); //obj.StaticFunc(); mangled_name_of_X_StaticFunc(); // ptr->StaticFunc(); mangled_name_of_X_StaticFunc(); // X::StaticFunc();/FONT>
X obj; X* ptr = &obj; obj.NormalFunc(); ptr->NormalFunc();/FONT>
mangled_name_of_X_NormalFunc(&obj); //obj.NormalFunc(); mangled_name_of_X_NormalFunc(ptr); // ptr->NormalFunc();/FONT>
X obj; X* ptr = &obj; X& ref = obj; ptr->VirtualFunc(); ref.VirtualFunc();/FONT>
( *ptr->vptr[2] )(ptr); ( *ptr->vptr[2] )(&ref);/FONT>
XX::XX() { // 編譯器擴充代碼所要做的工作 1、 調用父類X的缺省構造函數 2、 設定vptr指向XX類虛函數表 3、 調用String類的缺省構造函數構造m_strName };/FONT>
效率不高的做法 高效率做法 void Function( XX xx ) void Function( const XX& xx ) { { //函數體 //函數體 } }/FONT>
效率不高的做法 高效率做法 void Function( bool bCache ) void Function( bool bCache ) { { //函數體 //函數體 XX xx; if( bCache ) if( bCache ) {// do something without xx { return; // do something without xx } return; } //對xx進行操作 XX xx; //對xx進行操作 … return; return; } }/FONT>
效率不高的做法 高效率做法 void Function( const XX& xx ) void Function( const XX& xx ) { { XX cache; XX cache = xx; cache = xx ; } }/FONT>
效率不高的做法 高效率做法 XX::XX() XX::XX() : m_strName( "" ) { { m_strName = ""; … … } }/FONT>
?
posted on 2006-09-20 19:19 楊粼波 閱讀(861) 評論(0) 編輯 收藏 引用 所屬分類: C++
Powered by: C++博客 Copyright © 楊粼波