c++中不能区分重载的情况
2015-07-31 15:07
375 查看
Recordlookup(const Account &acct);
Recordlookup(const Account&); // parameter names are ignored
typedefPhone Telno;
Recordlookup(const Phone&);
Recordlookup(const Telno&); // Telno and Phone are the same type
Recordlookup(const Phone&, const Name&);
//default argument doesn't change the number of parameters
Recordlookup(const Phone&, const Name& = "");
// constis irrelevent for nonreference parameters
Recordlookup(Phone);
Recordlookup(const Phone); // redeclaration
ps:仅当形参是引用或指针时,形参是否为 const才有影响。
Recordlookup(Account&);
Record lookup(const Account&);// new function
const Account a(0);
Account b;
lookup(a); // callslookup(const Account&),没有则报错,即使有lookup(Account&);
lookup(b); // callslookup(Account&)精确匹配,如果没有则调用
lookup(const Account&),
注意:不能基于指针本身是否为 const 来实现函数的重载:
f(int*);
f(int*const); // redeclaration,等同于非引用、非指针变量
ps:const成员函数可以区分重载函数
Recordlookup(const Account&); // parameter names are ignored
typedefPhone Telno;
Recordlookup(const Phone&);
Recordlookup(const Telno&); // Telno and Phone are the same type
Recordlookup(const Phone&, const Name&);
//default argument doesn't change the number of parameters
Recordlookup(const Phone&, const Name& = "");
// constis irrelevent for nonreference parameters
Recordlookup(Phone);
Recordlookup(const Phone); // redeclaration
ps:仅当形参是引用或指针时,形参是否为 const才有影响。
Recordlookup(Account&);
Record lookup(const Account&);// new function
const Account a(0);
Account b;
lookup(a); // callslookup(const Account&),没有则报错,即使有lookup(Account&);
lookup(b); // callslookup(Account&)精确匹配,如果没有则调用
lookup(const Account&),
注意:不能基于指针本身是否为 const 来实现函数的重载:
f(int*);
f(int*const); // redeclaration,等同于非引用、非指针变量
ps:const成员函数可以区分重载函数
相关文章推荐
- c++中的引用(别名)
- C/C++_sizeof的本质与使用注意事项
- C语言经典算法例题求100-999之间的“水仙花数
- C语言编程入门——if的用法
- c/c++中运行外部程序
- 黑马程序员---iOS基础---C语言中的常见错误
- c语言mysql数据库事务开始、提交、回滚范例
- C语言编程入门——HelloWorld!
- c语言详解+例子1
- C、C++、C#、Java、php、python语言的内在特性及区别
- 一道逻辑推理题的C++实现
- 自相关函数及c++程序
- curllib上传文件c/c++
- C++导出函数,C++Invoke再次封装,C#调用
- C语言的标准化
- 在C语言中 i++与++i的区别
- C语言的inline
- C#与VC++数据类型对应关系
- c语言中的宏,#号##号,可变参数
- 动态规划之Jury Compromise