编译器无法选择适当的重载功能(导致C2666) [英] compiler unable to choose proper overloaded function (causes C2666)

查看:81
本文介绍了编译器无法选择适当的重载功能(导致C2666)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你有两个重载函数:


double double(double a,double b,double c);

int maximum(int a,int b,int c);


如果你将所有参数调用为maximum()为double,或者

全部为int,则它们可以正常工作。但是,如果你在参数

列表中将双打与int混合,它不知道要调用哪个(),但只有一个可能

可能匹配 - 带双打的那个。


我认为这不是一个bug,按照定义......但是,为什么?


Jason

解决方案

Jason Doucette写道:


如果你有两个重载函数:


double double(double a,double b,double c);

int maximum(int a,int b,int c) ;


如果你将所有参数调用为maximum()为double,或者

全部为int,则它们可以正常工作。但是,如果你在参数

列表中将双打与int混合,它不知道要调用哪个(),但只有一个可能

可能匹配 - 带双打的那个。


我认为这不是一个bug,按照定义......但是,为什么?



浮动积分转换(从double到int)和浮动

点转换(从int到double)具有同样的排名

作为重载决议。


V

-

请在通过电子邮件回复时删除资本''A'

我没有回复最热门的回复,请不要问


浮动积分转换(从double到int)和浮动


点转换(从int到double)具有相同的等级

作为重载解决方案。



好​​的。我并不认为从*到*
的隐含转换是*允许的,因为它们可能会丢失信息。


Jason


Jason Doucette写道:


> Floating-integral转换(从double到int)和浮动
点转换(从int到double)具有与重载决策相同的等级。



好​​的。我并不认为从*到*允许隐含的转换,因为它们可能会丢失信息。



如果总是不允许有潜在危险的东西,我们就不会b / b
有很多这种语言的功能。想象一下取消引用一个指针

不允许,因为(哦,不!)指针可能无效!


V

- -

请在通过电子邮件回复时删除资金''A'

我没有回复最热门的回复,请不要问


If you have two overloaded functions:

double maximum(double a, double b, double c);
int maximum(int a, int b, int c);

They work fine if you call maximum() with all arguments as doubles, or
all as ints. But, if you mix up doubles with ints in the argument
list, it doesn''t know which maximum() to call... but only one could
possibly match -- the one that takes doubles.

I assume this is not a bug, and is by definition... but, why?

Jason

解决方案

Jason Doucette wrote:

If you have two overloaded functions:

double maximum(double a, double b, double c);
int maximum(int a, int b, int c);

They work fine if you call maximum() with all arguments as doubles, or
all as ints. But, if you mix up doubles with ints in the argument
list, it doesn''t know which maximum() to call... but only one could
possibly match -- the one that takes doubles.

I assume this is not a bug, and is by definition... but, why?

Floating-integral conversions (from a double to an int) and floating
point conversions (from an int to a double) have the same rank as far
as overload resolution is concerned.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


Floating-integral conversions (from a double to an int) and floating

point conversions (from an int to a double) have the same rank as far
as overload resolution is concerned.

Ok. I didn''t think that implicit conversions from a double to an int
were *ever* allowed, since they can lose information.

Jason


Jason Doucette wrote:

>Floating-integral conversions (from a double to an int) and floating
point conversions (from an int to a double) have the same rank as far
as overload resolution is concerned.


Ok. I didn''t think that implicit conversions from a double to an int
were *ever* allowed, since they can lose information.

If something potentially dangerous would always be disallowed, we''d not
have many feature of the language. Just imagine dereferencing a pointer
not allowed because (Oh, no!) the pointer can be invalid!

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


这篇关于编译器无法选择适当的重载功能(导致C2666)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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