在VC ++中使用不同的参数多次声明相同的函数 [英] Declaring same function multiple times with different parameters in VC++

查看:137
本文介绍了在VC ++中使用不同的参数多次声明相同的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在VC ++中用不同的参数多次声明相同的函数是否可以?



例如:

第一个函数将是:

函数(数据类型为long int,length long int, Void * data)



第二个函数将是:

函数(数据类型为long int,length long int,Id int,Void * data )



如果用相同的参数多次声明相同的函数但参数的数据类型不同?

例如:

第一个函数将是:

函数(数据类型为long int,length long int,Void * data)



第二个函数将是:

函数(数据类型为long int,length long int,Const Struct * data)



我没有语法错误,但我想弄清楚这是正确的使用方法吗?

Is it OK to declare same function many times with different parameters in VC++?

e.g:
first function will be :
Function(datatype as long int, length long int, Void * data)

second function will be :
Function(datatype as long int, length long int, Id int, Void * data)

How about declaring same function with same parameters many times but different data types of parameters ?
e.g:
first function will be :
Function(datatype as long int, length long int, Void * data)

second function will be :
Function(datatype as long int, length long int, Const Struct * data)

I am not getting syntax errors, but i want to clarify is this correct way of using?

推荐答案

1)缺少返回类型; 2)C ++是一种区分大小写的语言,因此Const和Struct不会编译,3)......不,这就够了。很明显,你试图用C ++编程而不用阅读基础知识。不,没有奇迹这样的事情。



具有不同参数的相同功能不是同一个功能。这是一组完全不同的函数,恰好具有相同的名称(有其便利性),如果可能,由调用表达式识别的签名由编译器决定调用哪一个。声明,定义和调用此类函数没有问题。



-SA
1) return type is missing; 2) C++ is a case-sensitive language, so "Const" and "Struct" won't compile, 3) … no, that's enough. It's pretty obvious that you are trying to program in C++ without reading even about the basics. No, there is no such thing as miracle.

"Same function with different parameters" is not the same function. This is a set of totally different function which happen to have the same name (which has its convenience), and which one to call is decided by a compiler by the signatures recognized from the call expression, if possible. There is are no problems with declaring, defining and calling such functions.

—SA


这篇关于在VC ++中使用不同的参数多次声明相同的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆