- 0
- 0
- 约9.78千字
- 约 37页
- 2021-11-30 发布于安徽
- 举报
Cost of functions Runtime overhead caused by function calls Pushing arguments and CPU registers into the stack Transferring control to and from a function Inline function (内联函数) A function not called by the caller. The compiler copies the function code in line at the point of each invocation. Inline Functions * inline type func name (para list) Used for short functions rather than long functions Copying long function codes lengthens the program A long “inline” function may be treated as a common function: the “inline” is ignored. The compiler makes such decisions Notes for Inline Functions * Parameters declared with default values Default Arguments (缺省参数) * type name(type para1, …, type parai=defaultvalue, …) { //Function body Statements; } Note: Default arguments must be declared at last int max(int x, int y=0, int z=0){ … } int max(int x, int y=0, int z){ … } E.g.: Program4.2 Const Arguments In c++, an argument to a function can be declare as constant. To protect the arguments from changes by the function. E.g. int strlen(const char *p); int length(const string s); Overloading (重载): two functions within one file with The same name, but Different parameter lists The types and/or the number of arguments Function Overloading * int max(int x, int y){ … } float max(float x, float y){ … } int max(int x, int y, int z){ … } Different parameter type Different parameter number Return value type does not matter!!! Implicit type conversion may be done in function invocation Type Conversion and Overloading * float max(float x, float y){ float z; if(x=y) z=x; else z=y; return z; } int main(){ int a=3, b=5; coutmax(a,b)endl; } long double double float unsigned long long unsigned int int Function version determination Which version of a overloaded function should be called for an invocation? First: the one with exactly matching parameter list Second: the one matching after typ
您可能关注的文档
- 高等数学课件:9-5 二阶线性常系数微分方程.ppt
- 高等数学课件:9-7常系数线性微分方程组.ppt
- 高等数学课件:10.1向量及其运算(1-30).ppt
- 高等数学课件:10.2 空间直角坐标系与向量代数(1-24).ppt
- 高等数学课件:10.3 平面与直线.ppt
- 高等数学课件:10.4.1曲面及其方程.ppt
- 高等数学课件:10.4.2二次曲面.ppt
- 高等数学课件:10.5向量函数 空间曲线.ppt
- 高等数学课件:10-1 收敛原理与数项级数.ppt
- 高等数学课件:10-2 正项级数.ppt
- 2025年准格尔旗三年级数学第一学期期末考试模拟试题含解析.doc
- 浙江省衢州市名校2024年八上物理期末复习检测模拟试题含解析.doc
- 哈尔滨城市职业学院《行进管乐训练》2023-2024学年第一学期期末试卷.doc
- 福州黎明职业技术学院《智慧检验医学》2023-2024学年第一学期期末试卷.doc
- 2024-2025学年广东省深圳市罗湖区文锦中学九上化学期末检测模拟试题含解析.doc
- 山东省德州市庆云县统编版六年级下册期末考试道德与法治试卷【含答案】.pdf
- 山东省德州市平原县统编版六年级下册期末考试道德与法治试卷【含答案】.pdf
- 山东省德州市宁津县统编版六年级下册期末考试道德与法治试卷【含答案】.pdf
- 山东省德州市陵城区统编版六年级下册期末考试道德与法治试卷【含答案】.pdf
- 山东省德州市经济技术开发区统编版六年级下册期末考试道德与法治试卷【含答案】.pdf
原创力文档

文档评论(0)