功能签名 [英] Function Signatures

查看:97
本文介绍了功能签名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个函数:

void round(double& num)


在同一个类文件中,我还包含了cmath头文件管理器

当我尝试编译时,我得到一个模糊错误。如果我正确地记得

,那么圆形文件是否有签名:

双轮(双)?

所以不会因为我通过引用传递,因此我的情况有所不同,因为

与cmath头文件的传递值相反?或者我是否已经误解了这方面的重载?

I created a function:
void round(double & num)

In the same class file I have also included the cmath header filer
When I try to compile I get an ambiguity error. If I recall
correctly, doesn''t the cmath round file have a signature:
double round(double)?
So would not mine be different since I am passing by reference as
opposed to the pass by value of the cmath header file? Or have I been
misunderstanding this aspect of overloading?

推荐答案

da ***** @ digitalfiling.com 写道:
da*****@digitalfiling.com wrote:

我创建了一个函数:

void round(double& num)


在同一个类文件中我还包含了cmath头文件管理器

当我尝试编译我得到一个歧义错误。如果我正确地记得

,那么圆形文件是否有签名:

双轮(双)?

所以不会因为我通过引用传递,因此我的情况有所不同,因为

与cmath头文件的传递值相反?或者我是否已经误解了这方面的重载?b
$ b
I created a function:
void round(double & num)

In the same class file I have also included the cmath header filer
When I try to compile I get an ambiguity error. If I recall
correctly, doesn''t the cmath round file have a signature:
double round(double)?
So would not mine be different since I am passing by reference as
opposed to the pass by value of the cmath header file? Or have I been
misunderstanding this aspect of overloading?



如果你把b + b给它加倍,你期望编译器确定调用哪个函数?


5月1日上午9:40,Rolf Magnus< ramag ... @ t-online.dewrote:
On May 1, 9:40 am, Rolf Magnus <ramag...@t-online.dewrote:

dani ... @ digitalfiling.com写道:
dani...@digitalfiling.com wrote:

我创建了一个函数:

void round(double& amp ; num)
I created a function:
void round(double & num)


在同一个类文件中我还包含了cmath头文件管理器

当我尝试编译时得到歧义错误。如果我正确地记得

,那么圆形文件是否有签名:

双轮(双)?

所以不会因为我通过引用传递,因此我的情况有所不同,因为

与cmath头文件的传递值相反?或者我是否已经误解了这方面的重载?b
$ b
In the same class file I have also included the cmath header filer
When I try to compile I get an ambiguity error. If I recall
correctly, doesn''t the cmath round file have a signature:
double round(double)?
So would not mine be different since I am passing by reference as
opposed to the pass by value of the cmath header file? Or have I been
misunderstanding this aspect of overloading?



如果你想要编译器确定调用哪个函数

给它一个加倍?


How do you expect the compiler to determine which function to call if you
give it a double?



我的问题是,编译器是否考虑通过引用传递

与确定签名时的传递值不同?

My questions is, "Does the compiler not consider passing by reference
different from passing by value when determining a signature?"


2007年5月1日星期二07:36:42 -0700,daniell写道:
On Tue, 01 May 2007 07:36:42 -0700, daniell wrote:

我创建了一个函数:

void round(double& num)


在同一个类文件中我还包含了cmath头文件管理器当

我尝试编译我得到歧义错误。如果我没记错的话,

这个圆形文件没有签名:

双轮(双)?

所以不会因为我通过引用传递,因此我的情况有所不同,因为

与cmath头文件的传递值相反?或者我是否已经误解了这方面的重载?b
$ b
I created a function:
void round(double & num)

In the same class file I have also included the cmath header filer When
I try to compile I get an ambiguity error. If I recall correctly,
doesn''t the cmath round file have a signature:
double round(double)?
So would not mine be different since I am passing by reference as
opposed to the pass by value of the cmath header file? Or have I been
misunderstanding this aspect of overloading?



但是当你打电话给你的函数时,请说:


double x = 3.27;

round(x);


编译器怎么知道你想要哪一轮()?


最简单的方法是将你的函数放在一个命名空间,或简单地给它

a不同的名字。


-

Lionel B

But when you call your function, say:

double x = 3.27;
round(x);

how could the compiler know which round() you intended?

Easiest would be to place your function in a namespace, or simply give it
a different name.

--
Lionel B


这篇关于功能签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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