讀書筆記之:C++程式設計原理與實踐(ch27:C與C++的區別)[+++]

來源:互聯網
上載者:User

第27章 C語言

1. C與C++




2. C與C++的相容性



3. C不支援的C++特性




 

4. C中函數與C++的區別:不支援函數重載


5. 函數參數檢查




6. 函數定義




 

7. 在C++中調用C和在C中調用C++



 


 

8. 函數指標


View Code /*

//

// This is example code from Chapter 27.2.4 "Pointers to functions" of

// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup

//

*/

/*----------------------------------------------------------------------------*/

struct Shape1 {

    enum Kind { circle, rectangle } kind;

    /* ... */

};

/*----------------------------------------------------------------------------*/

void draw(struct Shape1* p)

{

    switch (p->kind) {

case circle:

    /* draw as circle */

    break;

case rectangle:

    /* draw as rectangle */

    break;

    }

}

/*----------------------------------------------------------------------------*/

int f(struct Shape1* pp)

{

    draw(pp);

    /* ... */

}

/*----------------------------------------------------------------------------*/

typedef void (*Pfct0)(struct Shape2*); 

typedef void (*Pfct1int)(struct Shape2*,int);

/*----------------------------------------------------------------------------*/

struct Shape2 {

    Pfct0 draw;

    Pfct1int rotate;

    /* ... */

};

/*----------------------------------------------------------------------------*/

void draw1(struct Shape2* p)

{

    (p->draw)(p);

}

/*----------------------------------------------------------------------------*/

void rotate(struct Shape2* p)

{

    (p->rotate)(p,90);

}

/*----------------------------------------------------------------------------*/

int f1(struct Shape * pp)

{

    draw(pp);

    /* ... */

}

/*----------------------------------------------------------------------------*/

9. C/C++結構簽名字空間的差別


 

10. C/C++在關鍵字上的差別


11. C/C++在變數定義上的區別



12. C風格類型轉換



13. void* 轉換


14. 枚舉


15. 名字空間


16. 動態記憶體分配




 

17. C風格字串




 

18. C風格字串與const



19. 位元組操作


20. 執行個體:strcpy


21. 風格問題


22. 輸入輸出







23. 檔案


24. 常量與宏



25. 宏



26. 類函數的宏



27. 不要使用文法宏


28. 條件編譯


 

 


 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.