Function overloading in C++
来源:互联网 发布:软件qa面试题 编辑:程序博客网 时间:2024/06/11 01:41
Function overloading, which seems to be a simple topic, is in fact much more complicated than we expect. An excellent book <C++ Primer> (I read the third edition) provides a full cover on it.
In short, there are two cases of function overloading, the normal function overloading in a certain scope and the member function overloading in a class scope. The compiler will follow three steps to select a correct form of a particular function call.
First of all, the compiler consider all the functions with the same name of that function call and visible at the calling point as the candidate functions. Meantime, figure out the number and the types of the real parameters of that call. In this step, the meanings of visible are different between overloading in a certain scope and in a class scope. Secondly, compare the number and the types with every candidate function's parameter list, to get the viable functions for that call. Any candidate function whose parameter list matches the real parameter list, which means that the real parameters have the same type with the corresponding ones in the parameter list of one function in three cases: accurate match, standard convertion, and user-defined convertion, can be a viable function of that real call. Finally, the best match among the viable functions is selected to finish that call. The rule for best match is that accurate match is better than standard convertion, and standard convertion is better than user-defined convertion.
To get more details about function overloading, I strongly recommend you to turn to <C++ Primer>. The related chapters in the third edition are: chapter 9 (the whole chapter focusing on the normal function overloading), chapter 15 (the whole chapter focusing on the member function overloading and the operator overloading of class), and chapter 19 part 3 (focusing on the overloading problem in the hierarchy of inheritance).
- Function overloading in C++
- Overloading Functions in C
- Function Overloading
- Function overloading
- Function Inheritance and Overriding and Function Overloading In D
- 读书笔记-Thinking in C++-第7章 函数重载和默认参数Function Overloading &Default Arguments
- Comparison between overloading operators in member function and in friend function
- UVa 11032 Function Overloading
- programming error (function overloading)
- 1638 function overloading
- Fatal error: Uncaught exception 'PHPExcel_Exception' with message 'Multibyte function overloading in
- const overloading in C++
- Overloading Methods in WCF
- UDF overloading in spark
- Function overloading and const keyword
- Name Mangling and Function Overloading
- C++ Overloading (Operator and Function)
- memcached.c: In function ‘add_iov’:
- 7种js分页效果
- 条件指示符#ifdef
- 推荐两篇文章
- GDB调试精粹及使用实例
- debug与release区别和使用的常见错误
- Function overloading in C++
- c语言中static 用法总结
- solaris e1000g driver bug
- JBoss3.0 下配置和部署EJB简介
- 软件需求分析
- 堆和栈的区别
- Web Services开发体会和在项目中的教训
- ExtJS 序言一
- 内存对齐与 struct型数据的内存布局