读书笔记之:C++程序设计原理与实践(ch27:C与C++的区别)[+++]

第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. 条件编译

 

 

 

posted @ 2012-04-10 17:46  Mr.Rico  阅读(1324)  评论(0编辑  收藏  举报