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

C++ Programmer's Cookbook

{C++ 基礎} {C++ 高級} {C#界面,C++核心算法} {設計模式} {C#基礎}

c++ effective心得

1.Operator overloading

 

一般的:  c& c::operator=(const c&){。。。。return *this;};   --------格式  運算符的重載
   w = x = y = z = "hello";//可以返回引用,效率高
   a+b+c+d     //必須返回類,而不是返回引用
   c c::operator=(const c &){ 。。。。。。return *this;};
  
Operators that can be overloaded
+, -, *, /, %, ^, &, +=,-=,*=,/=, (), [], >>, ==,=,->,++,--, ->*, … new, delete
Operators that can not be overloaded
., ::, ?:, .*
//Notes for ++, -- operator
區別:
 T& operator ++() //prefix ++a
 T operator++(int) //postfix a++


一般情況下幾乎總要遵循operator=輸入和返回的都是類對象的引用的原則.
必須返回一個對象時不要試圖返回一個引用,當需要在返回引用和返回對象間做決定時,你的職責是選擇可以完成正確功能的那個。至于怎么讓這個選擇所產生的代價盡可能的小,那是編譯器的生產商去想的事。

2.
const成員函數不被允許修改它所在對象的任何一個數據成員。mutable在處理“bitwise-constness限制”問題時是一個很好的方案,但它被加入到c++標準中的時間不長,所以有的編譯器可能還不支持它。
explicit表示必須顯示的調用該函數。

3.void including more times
#findef
#define

#endif

等價于
#progma once


4  .struct
                             #pragma pack(pop, n)
struct Employee{
 char cName[5];
 short  nAge;
        float  dSalary;
 bool  bMarried;
};
sizeof(Employee) depends on struct member alignment. Default is 4 bytes alignment. sizeof(Employee) = 16
2 bytes data wants to start from even address, 4 bytes data wants to start from address that is 4 times, 1 byte data can start from any address
我們可以用以下改變默認的對齊方式。
#pragma pack(pop, n)

5。enum :It can define a set of const values.

6。In fact, C++ compiler creates a global function for each member function, and add another parameter whose type is our class. 一般位類名_函數名_參數列表

7。constructor   ※   deconstructor

Copy Constructor 
Copy constructor is a constructor that has a parameter whose type is class reference.
and the class reference is const.
eg:
CRectangle( const CRectangle& other)
eg:
   CComplex a;
   CComplex b=a; // Copy constructor is invoked
   b=a; //Assignment operator is invoked

Converting Constructor
一般定義位explicit函數,必須被顯示的調用


8。const in class
  4 cases in a class
 const int member;只能在初始化列表里進行初始化
 int funct( const int nFactor,…);參數位常熟,在函數種不可被修改
 const int func(…); 返回的值位常熟不可以再被賦值和修改
 int func(…) const; 常函數,不可以修改所在類的成員,要修改的成員必須有mutable關鍵字


9。inline
You can see there is no function calling in assembly.
A function defined within a class definition is an inline function.
Although a function is inline, that whether to expend or not depends on compiler or its settings.一般函數里有循環的系統認為不內聯
10.  Member-initializer-list
Const, reference and base class constructor (that has arguments) must be initialized or called in member-initializer-list
Members are initialized by order that they are defined in class definition, not by order their initializers are in member-initializer-list.
eg:
CCircle::CCircle() : PI(3.14159), m_dOrgX(0.0), m_dOrgY(0.0)
{
}
基類的初始化,按照子類定義時的順序,不時初始化列表的順序

11。 class Default functions
Constructor [do nothing]
Copy constructor [bitwise copy]
Destructor ( ~ ) [do nothing]
Assignment operator ( = ) [bitwise copy]
Address operator ( & )
Dereference operator ( * )

//當有指針是自己定義拷貝構造和賦值
eg:
        if(other.m_pBuffer!=NULL) {
 m_pBuffer=new TCHAR[tcslen(other.m_pBuffer)+1];
 tcscpy(m_pBuffer,other.m_pBuffer);}

12 this 指針
Point lower;
lower.setX(20).setY(30).doubleMe() ;
因為:
     Point& setX(int x) { _x = x; return *this;}  
     Point& setY(int y) { _y = y; return *this;}  
     void doubleMe()
 {  _x *= 2;
  _y *= 2;  
 }

13。    const   static     int PI=1;類中的成員直接賦值,只有這一種情況可以,必須為int.

        double CCircle::PI = 1.0;類中的靜態成員初始化必須再類外,而且還的有類型, 如前面.
        靜態成員的初始化不能再構造函數中進行!

14.  Dynamic_cast
The dynamic_cast is used for safe casting from a pointer to a base class to a pointer to a derived class, often referred to as safe down casting. It is used when one must use the features of the derived class that are not present in the base class.

typeid            typeid( object );
The typeid operator returns a reference to a type_info object that describes `object`.

If the expression is of class type and the class contains one or more virtual member functions, then the answer may be different than the type of the expression itself. For example, if the expression is a reference to a base class, the typeid operator indicates the derived class type of the underlying object.

PTTI運行時刻類型識別允許“用指向基類的指針或引用來操作對象”的程序能夠獲取到“這些指針或引用所指的對象”的實際派生類型。
1. Dynamic_cast它允許在運行時刻進行類型轉換,從而使程序能夠在一個類層次結構中安全地轉換類型,把基類指針轉化成派生類指針,或把指向基類的左值轉換成派生類的引用,當然只有在保證轉換能夠成功的情況下可以。
2. typeid操作符,它指出指針或引用指向的對象的實際派生類型。它在程序中可以用于獲取一個表達式是一個類類型,并且含有一個或多個虛函數成員,則答案會不同于表達式本身的類型。例如,如果表達式是一個基類的引用,則typeid會指出底層對象的派生類類型。


15. What exceptions can a function throw if it has an exception specification of the form throw()?  (6’) throw all kinds of exceptions
If  it has no exception specification?
What means the syntax: catch (…) catch all types of exceptions

posted on 2005-11-09 12:56 夢在天涯 閱讀(1874) 評論(2)  編輯 收藏 引用 所屬分類: CPlusPlus

評論

# re: c++ effective心得 2006-08-17 12:26 keyws

T& operator ++() //prefix ++a
T operator++(int) //postfix a++
怎么解釋這個?即編譯器如何決定調用哪個?

  回復  更多評論   

# re: c++ effective心得 2008-10-14 14:33 ggz

@keyws
一個是++a 一個是a++  回復  更多評論   

公告

EMail:itech001#126.com

導航

統計

  • 隨筆 - 461
  • 文章 - 4
  • 評論 - 746
  • 引用 - 0

常用鏈接

隨筆分類

隨筆檔案

收藏夾

Blogs

c#(csharp)

C++(cpp)

Enlish

Forums(bbs)

My self

Often go

Useful Webs

Xml/Uml/html

搜索

  •  

積分與排名

  • 積分 - 1815005
  • 排名 - 5

最新評論

閱讀排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
              国产综合自拍| 免费观看久久久4p| 欧美日韩亚洲视频| 免费成人av| 欧美日韩一二三四五区| 欧美韩国日本一区| 国产精品日韩一区二区三区| 国产精品久久99| 国产主播一区| 亚洲精品韩国| 欧美专区日韩专区| 亚洲国产精品电影| 欧美成年人视频网站欧美| 亚洲九九精品| 久久精品国产成人| 欧美日韩视频一区二区三区| 牛牛国产精品| 久久av在线看| 一区二区三区视频在线观看| 久久亚洲图片| 亚洲黄色片网站| 久久亚洲春色中文字幕| 亚洲国产精品第一区二区| 久久免费黄色| 国产精品影音先锋| 欧美一区二区三区免费看| 欧美国产91| 午夜影院日韩| 国产喷白浆一区二区三区| 亚洲午夜一区二区| 久久综合伊人| 欧美日韩a区| 亚洲永久字幕| 亚洲免费视频中文字幕| 欧美日韩在线视频首页| 香蕉精品999视频一区二区| 美女精品一区| 久久夜色精品国产亚洲aⅴ | 国产精品第2页| 亚洲一级电影| 久久九九精品| 欧美中在线观看| 欧美成人国产| 亚洲青涩在线| 亚洲自拍三区| 国产综合香蕉五月婷在线| 欧美一区二区三区精品| 久久亚洲一区二区三区四区| 亚洲欧美中日韩| 欧美国产视频在线观看| 午夜精品久久久99热福利| 国产精品成人一区二区网站软件 | 一区二区三欧美| 亚洲综合视频1区| 91久久国产综合久久| 亚洲乱码久久| 在线成人www免费观看视频| 在线一区二区日韩| 日韩视频国产视频| 午夜在线视频观看日韩17c| 在线综合亚洲| 免费成人黄色av| 久久天天狠狠| 欧美丰满高潮xxxx喷水动漫| 欧美一区二区日韩一区二区| 欧美伦理a级免费电影| 亚洲精选一区| 亚洲欧美日韩专区| 欧美性jizz18性欧美| 亚洲精品美女久久7777777| 国产一区二区三区自拍| 香蕉av福利精品导航| 欧美一区91| 国产精品乱码| 麻豆久久婷婷| 欧美福利视频| 亚洲欧美色婷婷| 亚洲精品欧美精品| 欧美日韩伦理在线免费| 久久久免费精品视频| 最新成人在线| 蜜桃视频一区| 久久免费的精品国产v∧| 欧美一区二区三区另类| 欧美激情欧美狂野欧美精品| 亚洲综合日本| 狠狠色狠狠色综合日日五| 欧美视频网站| 久久久久久综合| 欧美一站二站| 久久久久免费视频| 欧美一区中文字幕| 亚洲欧美成人综合| 亚洲男人影院| 午夜视频久久久| 国产精品制服诱惑| 国产精品一区二区在线观看| 久久久水蜜桃| 免费观看日韩| 久久久久久自在自线| 猛男gaygay欧美视频| 麻豆免费精品视频| 欧美在线观看一区二区| 欧美在线地址| 欧美在线视频日韩| 欧美本精品男人aⅴ天堂| 久久国产欧美| 麻豆精品国产91久久久久久| 久久久国产精品一区二区中文| 一区二区三区欧美成人| 亚洲欧洲一区二区在线观看| 一本色道久久99精品综合| 一区二区三区精品国产| 亚洲欧美日本另类| 免费久久99精品国产自在现线| 另类图片综合电影| 国产精品亚洲片夜色在线| 国产欧美日韩亚洲一区二区三区| 亚洲精品一二区| 欧美一区二区三区精品电影| 久久久777| 欧美成人国产va精品日本一级| 99av国产精品欲麻豆| 日韩视频一区二区三区在线播放| 亚洲精品1234| 亚洲影音一区| 亚洲日本欧美日韩高观看| 亚洲高清不卡在线观看| 一区二区三区日韩精品| 欧美成在线观看| 欧美日韩一区二区三区在线观看免| 欧美日韩第一区日日骚| 亚洲欧洲精品一区二区| 亚洲免费在线播放| 久久久91精品国产| 欧美一区二区三区四区高清| 欧美亚男人的天堂| 亚洲一区二区视频在线| 你懂的视频一区二区| 亚洲欧美成人一区二区在线电影| 欧美午夜不卡在线观看免费 | 亚洲美女免费视频| 亚洲美女av在线播放| 久久精品视频在线| 久久精品av麻豆的观看方式| 亚洲第一精品福利| 午夜精品视频网站| 亚洲午夜av电影| 久热精品视频在线观看| 午夜精品亚洲一区二区三区嫩草| 国产日韩欧美麻豆| 久久精品99| 欧美日本一区二区高清播放视频| 一本色道久久加勒比88综合 | 欧美日韩在线播放| 亚洲午夜激情免费视频| 亚洲欧美怡红院| 亚洲国产精品一区二区www| 午夜精品影院| 亚洲一区二区三区高清不卡| 亚洲美女免费视频| 欧美日韩中文在线| 亚洲精品影院| 国产真实乱子伦精品视频| 欧美电影在线观看| 国产日韩欧美视频| 久久xxxx精品视频| 欧美高清视频| 亚洲视频免费在线| 欧美激情五月| 欧美电影免费网站| 国产精品你懂得| 亚洲视频一区二区在线观看 | 日韩亚洲视频在线| 亚洲天堂av高清| 亚洲最新在线| 欧美.www| 欧美韩日一区二区| 国产欧美日韩视频| 欧美在线免费观看| 中文国产成人精品| 国产精品久久久久久亚洲毛片| 欧美a一区二区| 黄色一区二区三区四区| 亚洲一二三区在线| 欧美一区二区三区在线观看视频| 国产精品av一区二区| 亚洲精品久久久久久一区二区| 亚洲欧洲日产国产综合网| 欧美国产日韩视频| 亚洲激情在线激情| 亚洲精品一区在线| 免费看亚洲片| 亚洲精品女人| 国产一级一区二区| 欧美日韩第一页| 亚洲综合另类| 欧美一区二区视频在线观看2020 | 久久精品国产久精国产爱| 久久五月激情|