C++按下列三个步骤的先后顺序找到匹配并调用函数:
(1)寻找一个严格匹配,如果找到了,就用那个函数;
(2)通过相容类型的隐式转换寻求一个匹配,如果找到了,就用那个函数;
(3)通过用户定义的转换寻求一个匹配,若能查出有唯一的一组转换,就用那个函数。
例如,重载函数print的匹配:
void print(double);
void print(int);
void func() {
print(1); //匹配int;-----顺序1
print(1.0); //匹配double;-----顺序1
print('a'); //匹配int;-----顺序2
print(3.1415f); //匹配double;-----顺序2
}
C++允许int型容到long型,int型容到double型的隐式转换。但若必须在两者之间抉择时,则会引起错误。
例如
void print(long a);
void print(double a);
void func(int a) {
print(a); //这里的print要匹配哪一个呢?
}
为避免匹配冲突,在调用时,应显示表明是print(long(a))还是print(double(a))。
分享到:
相关推荐
1.error C2733: second C linkage of overloaded function '_interlockedbittestandset' not allowed 2.atlcom 中的 rgs…… 场景: 1.在VS2005 SP1 之上安装 Microsoft SDK 7.0 2.同PC上安装VS2005 SP1与VS2008/...
在加强社区内部的管理中,拥有可以对社区内部进行监控的系统可以节省下来很大一部分人力,并且比人为的巡逻更加可靠、安全。社区视频监控系统主要是利用摄像头和视频采集卡进行视频监控的,本社区视频监控系统主要...
今天小编就为大家分享一篇关于json error: Use of overloaded operator [] is ambiguous错误的解决方法,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
NULL 博文链接:https://20120923lina.iteye.com/blog/2258119
weblogic学习 weblogic节点配置管理器很详细的文档,一看就明白
《Zabbix监控系统深度实践》是一本由浅入深,全面讲解Zabbix应用与原理的技术书籍,也是作者多年实战经验的总结和浓缩。在概念篇,从一个简单但完整的入门案例讲起,案例中有最基本的概念介绍,通过案例帮助那些只要...
VB.NET uses overloaded forms of the same function, and this is an important difference you have to keep in mind as you work with the built-in functions. If you omit an optional argument, you must ...
用于XP SP3的重载内核,用WDK7.1.0编译通过。可在虚拟机,物理机使用
overloaded functions;anonymous functions;function structs;reference parameters;object lifetime operations;namespaces;modules;concepts; andcompiler introspection.示例代码:(import cstdio) (def main...
You can declare functions in a way that allows the compiler to expand them inline rather than calling them through the usual function call mechanism. Pros: Inlining a function can generate more ...
希望大家多下载,我的积分不够下载我需要的资源,当然这也是好东西啦。
该项目旨在将尽可能多的内核项目集中在一起,在可能的情况下消除冲突,以便实验性内核项目可以更安全地获得更大的曝光度,并可以在更多不同的条件下对这些项目进行测试
Connection matches did not process proxy user expressions (user1[user2]@database) correctly for the application background DBMS_Jobs could not be edited on Oracle19 (‘xxxx’ is not a valid
64位版本的 PLSQL 正式版,只能运行在64位系统中,...Connection matches did not process proxy user expressions (user1[user2]@database) correctly for the application background DBMS_Jobs could not be edited
错误 1 error C2668: 'sqrt' : ambiguous call to overloaded function d:\wordplay\c++\范例\fractral递归方法画分图形\stdafx.cpp 19 错误 2 fatal error C1903: unable to recover from previous error(s); ...
A_New_Variant_of_the_Matsumoto-Imai_Cryptosystem_t
WOLK是稳定的开发内核,其中包含许多项目中的许多有用补丁。 目标:稳定性,可伸缩性,性能,最重要的是:安全性。
added: New overloaded Add method in TNxColumns class. Duplicate exiting column and add it into list. added: LastAdded property in TNxColumns class. added: RevertStyle method in TNxCustomColumn class. ...
wpf开发教程.doc wpf入门白皮书.pdf
overloaded_methods 的灵感来自于 erlang 模式匹配。 基本上,这个想法是您可以根据参数的各个方面指定一个方法和几个代码块。 下面是一个例子: overload_method :even_odd do | m | m . when { | number | ...