- 2
- 0
- 约1.41万字
- 约 64页
- 2021-11-30 发布于安徽
- 举报
* * * * * * * * * * * * * A taste of C++: Function Overloading Function overloading(函数重载:功能相近的函数在相同的作用域内以相同函数名定义) Functions with same name and different parameters Overloaded functions should perform similar tasks Function to square ints and function to square floats int square( int x) {return x * x;} float square( float x ) { return x * x; } Program chooses function by signature(签名) Signature determined by function name and parameter types Type safe linkage - ensures proper overloaded function called Note: 1)必须是同名函数 2)必须是不同的形参定义 个数上不同 类型上不同 3)不能只是返回类型上不一样 重载函数的调用匹配依次按照下列规则判断 精确匹配:参数匹配而不做转换,或者只是做微不足道的转换,如数组名到指针、函数名到指向函数的指针、T到const T; 提升匹配:即整数提升(如bool 到 int、char到int、short 到int),float到double 使用标准转换匹配:如int 到double、double到int、double到long double、Derived*到Base*、T*到void*、int到unsigned int等等; 使用用户自定义匹配; 使用省略号匹配:类似printf中省略号参数 Function Overloading fig15_10.cpp Output: The square of integer 7 is 49 The square of double 7.5 is 56.25 Summary The history of Computers, Programming Software Computer Organization. Transistor, Gates Program vs. Software Computer components (Van Neumann Architecture), how programming languages work? Programming languages. history, abstract level Software development. steps, pseudo code, flow chart C++. why, history, a taste Thank you! * * * * * * * CSE1301 Sem 1-2006 * Lecture 1: Computer Systems Overview * CSE1301 Sem 1-2006 * Lecture 1: Computer Systems Overview * CSE1301 Sem 1-2006 * Lecture 1: Computer Systems Overview * CSE1301 Sem 1-2006 * Lecture 1: Computer Systems Overview * CSE1301 Sem 1-2006 * Lecture 1: Computer Systems Overview * CSE1301 Sem 1-2006 * Lecture 1: Computer Systems Overview * * * * * * * * * * * * * * * Abstraction Level (III) Here is the same program in JavaScript (rhino 1.7) Abstraction Level (IV) Other possible implementations: Python CoffeeScript With concepts sum and range, the code is clear and easy. That’s the power of abstraction. With concept reduce, mathematic
原创力文档

文档评论(0)