Function overloading and return type
In C++ and Java, functions can not be overloaded if they differ only in the return type.
For example, the following program C++ and Java programs fail in compilation.
(1)C++ Program
1 #include<iostream>
2 int foo()
3 {
4 return 10;
5 }
6
7 char foo() { // compiler error; new declaration of foo()
8 return 'a';
9 }
10
11 int main()
12 {
13 char x = foo();
14 getchar();
15 return 0;
16 }
(2)Java Program
1 // filename Main.java
2 public class Main
3 {
4 public int foo()
5 {
6 return 10;
7 }
8 public char foo()
9 {
10 // compiler error: foo() is already defined
11 return 'a';
12 }
13 public static void main(String args[])
14 {
15 }
16 }
the return type of functions is not a part of the mangled name which is generated by the compiler for uniquely identifying each function. The
No of arguments
Type of arguments &
Sequence of arguments
are the parameters which are used to generate the unique mangled name for each function. It is on the basis of these unique mangled names that compiler can understand which function to call even if the names are same(overloading).
Hence..... i hope u have understood what i am saying.[引自网友]
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
转载请注明:http://www.cnblogs.com/iloveyouforever/
Function overloading and return type的更多相关文章
- error C2556: 'const char &MyString::operator [](int)' : overloaded function differs only by return type from 'char &MyString::operator [](int)'
char & operator[](int i);const char & operator[](int i);/*const char & operator(int i);* ...
- [TypeScript] Infer the Return Type of a Generic Function Type Parameter
When working with conditionals types, within the “extends” expression, we can use the “infer” keywor ...
- Flask - 访问返回字典的接口报错:The view function did not return a valid response. The return type must be a string, tuple, Response instance, or WSGI callable, but it was a dict.
背景 有一个 Flask 项目,然后有一个路由返回的是 dict 通过浏览器访问,结果报错 关键报错信息 TypeError: 'dict' object is not callable The vi ...
- C++:Abstract class : invalid abstract return type for member function ‘virtual...’
#include <iostream> #include <cmath> #include <sstream> using namespace std; class ...
- function overloading/ declare function
Declare a function To declare a function without identifying the argument list, you can do it in thi ...
- c++11: trailing return type in functions(函数返回类型后置)
In C++03, the return type of a function template cannot be generalized if the return type relies on ...
- Return type declarations返回类型声明
PHP 7.新增了返回类型声明 http://php.net/manual/en/functions.returning-values.php 在PHP 7.1中新增了返回类型声明为void,以及类型 ...
- ES5 function & ES6 class & method type
ES5 function & ES6 class & method type ES5 function "use strict"; /** * * @author ...
- Function Overloading in C++
In C++, following function declarations cannot be overloaded. (1)Function declarations that differ o ...
随机推荐
- Linux wget 命令 使用总结
简介 wget命令用来从指定的URL下载文件.wget非常稳定,它在带宽很窄的情况下和不稳定网络中有很强的适应性,如果是由于网络的原因下载失败,wget会不断的尝试,直到整个文件下载完毕.如果是服务器 ...
- FAIL : Keyword 'BuiltIn.Log' expected 1 to 6 arguments, got 12(解决方法)
RF运行关键字:Run Keyword If ,log输出报错"FAIL : Keyword 'BuiltIn.Log' expected 1 to 6 arguments, got 12. ...
- 开源项目|Go 开发的一款分布式唯一 ID 生成系统
原文连接: 开源项目|Go 开发的一款分布式唯一 ID 生成系统 今天跟大家介绍一个开源项目:id-maker,主要功能是用来在分布式环境下生成唯一 ID.上周停更了一周,也是用来开发和测试这个项目的 ...
- 简易发号SQL,可用于生成指定前缀自增序列--改进版
使用merge语法实现新增or更新 首先创建表 CREATE TABLE Test.dbo.Increments ( Prefix varchar(50) NOT NULL, [MaxNum ] bi ...
- [bzoj1691]挑剔的美食家
考虑将奶牛和牧草放在一起,根据鲜嫩程度排序,那么显然就可以发现一个贪心策略:每一头奶牛一定选择当前剩余的最便宜且符合条件的牧草,然后用一个set维护价格即可 1 #include<bits/st ...
- .NET Core中的鉴权授权正确方式(.NET5)
一.简介 前后端分离的站点一般都会用jwt或IdentityServer4之类的生成token的方式进行登录鉴权.这里要说的是小项目没有做前后端分离的时站点登录授权的正确方式. 一.传统的授权方式 这 ...
- 前端jsdebug调试
前端如何像java一样的debug呢? 1.在js页面加入debugger next: function(){ debugger var type=this.quiz[this.progress].s ...
- 百胜中国使用Rainbond实现云原生落地的实践
百胜中国使用Rainbond实现云原生落地的实践 关于百胜中国 自从1987年第一家餐厅开业以来,截至2021年第二季度,百胜中国在中国大陆的足迹遍布所有省市自治区,在1500多座城镇经营着11023 ...
- [ Skill ] 图形化组件在注册 User Trigger 时需要注意的事情
https://www.cnblogs.com/yeungchie/ 使用 deRegUserTriggers 可以用来配置:当打开一个新窗口时,自动集成自定义的菜单.工具栏等等. 使用格式如下: d ...
- Codeforces 961F - k-substrings(二分+哈希)
Codeforces 题面传送门 & 洛谷题面传送门 介绍一种奇怪的 \(\Theta(n\log n)\) 的奇怪做法. 注意到这个"border 的长度必须是奇数"的条 ...