第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. 條件編譯