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 ...
 
随机推荐
- rocketmq有序消息的(四)
			
opic的有序消息已经成为mq的标配.而RocketMQ中是这样区分消息类型的, 普通消息也叫做无序消息,简单来说就是没有顺序的消息,而有序消息就是按照一定的先后顺序的消息类型.举个例子,produc ...
 - java读取大文件内容到Elasticsearch分析(手把手教你java处理超大csv文件)
			
现在需要快算分析一个2g的csv文件: 基于掌握的知识,使用java按行读取文件,批量导入数据到es, 然后利用es强大的聚合能力分析数据,2个小时搞定! package com.example.de ...
 - WPF嵌入Unity3D之后,unity3D程序的键盘和鼠标事件无法触发(3D程序的焦点无法激活)的解决方案
			
目前最通用的客户端调用3D的方式,就是WPF程序通过Process启动Unity3D的exe进程,直接上代码: //开启3D进程 internal void Create3DProcess(strin ...
 - Dapr-发布/订阅
			
前言 前篇文章对Dapr的状态管理进行了解,本篇继续对 订阅/发布 构建块进行了解. 一.定义: 发布订阅的概念来自于事件驱动架构(EDA)的设计思想,这是一种让程序(应用.服务)之间解耦的主要方式, ...
 - [bzoj1105]石头花园
			
首先$C/2=x_{max}+y_{max}-x_{min}-y_{min}=max(x_{max},y_{max})-min(x_{min},y_{min})+min(x_{max},y_{max} ...
 - rocketmq 精华
			
(ps:)通过本人语雀文档阅读体验更好哦--有目录 介绍 rocket mq 翻译成中文就是火箭消息队列,从名字就可以看出来,它是一个很快的消息队列... rocket mq 是 阿里巴巴研制的后面贡 ...
 - Maven pom常用plugins配置说明
			
maven-compiler-plugin 编译Java源码,一般只需设置编译的jdk版本 <plugin> <groupId>org.apache.maven.plugins ...
 - wireshatk_teach
			
wireshark抓包新手使用教程 Wireshark是非常流行的网络封包分析软件,可以截取各种网络数据包,并显示数据包详细信息.常用于开发测试过程各种问题定位.本文主要内容包括: 1.Wiresha ...
 - 7本Python必读的入门书籍,你看过吗?(附福利)
			
Python入门书籍不用看太多,看一本就够.重要的是你要学习Python的哪个方向,或者说你对什么方向感兴趣,因为Python这门语言的应用领域比较广泛,比如说可以用来做数据分析.机器学习,也可以用来 ...
 - (转载)Java生成和操作Excel文件
			
JAVA EXCEL API:是一开放源码项目,通过它Java开发人员可以读取Excel文件的内容.创建新的Excel文件.更新已经存在的Excel文件.使用该API非Windows操作系统也可以通过 ...