是否可以使用返回值重载? [英] Is it possible to overload with return values?

查看:60
本文介绍了是否可以使用返回值重载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这里我有两个功能。 void f(int,int)和另一个是

float f(int,int)。

是否可以使用返回值重载。


Thx,

kishore

Hi,
Here I am taking two functions. void f(int,int) and another one is
float f(int,int).
Is it possible to overload with return values.

Thx,
kishore

推荐答案

sk ******* @ yahoo.co.in 写道:

这里我正在承担两项职能。 void f(int,int)和另一个是浮点数f(int,int)。
是否可以用返回值重载。
Hi,
Here I am taking two functions. void f(int,int) and another one is
float f(int,int).
Is it possible to overload with return values.




No.

C ++标准(工作草案,2005-10-19)说:


13.1可重载声明

2某些函数声明不能​​重载:

a ??仅在返回类型上有所不同的函数声明不能​​超过


干杯

-

Mateusz? ?oskot
http://mateusz.loskot.net


不,根据其返回类型不能重载函数。


Ex:


void f(int);

int f(int);

main()

{

F(); //编译器如何知道在这种情况下调用

中的哪个函数。

}
sk ******* @ yahoo.co.in 写道:
No, it''s not possible to overload functions based on its return type.

Ex:

void f(int);
int f(int);
main()
{
f(); // How does the compiler know to call which function in
this case.
}
sk*******@yahoo.co.in wrote:

这里我有两个功能。 void f(int,int)和另一个是浮点数f(int,int)。
是否可以用返回值重载。

Thx,
kishore
Hi,
Here I am taking two functions. void f(int,int) and another one is
float f(int,int).
Is it possible to overload with return values.

Thx,
kishore






Sunil Varma写道:
Sunil Varma wrote:
不,它不可能基于它重载函数返回类型。
No, it''s not possible to overload functions based on its return type.




该语言允许的一件事与此类似 -

协变返回类型。不过,它更多地与覆盖有关。在

中,父母的成员函数被覆盖的情况下,更多

特定派生 (用硬币表示?)可以指定返回类型 - 即原始返回类型的

子级。为了说明:


struct A {};

struct B:A {};

struct C {A frobnicate() ; };

struct D:C {B frobnicate(); };


请注意,您还可以获得返回类型本身为

类的情况,例如:


A级{A frob(); };

B级:A {B frob(); };


除此之外,别忘了。


卢克



There is one thing permitted by the language which resembles this --
covariant return types. It has more to do with overriding, though. In
the case where a parent''s member function is overridden, a "more
specifically derived" (to coin a phrase?) return type -- that is, a
child of the original return type -- can be specified. To illustrate:

struct A {};
struct B : A {};
struct C { A frobnicate(); };
struct D : C { B frobnicate(); };

Note that you can also have the case where the return types are the
classes themselves, e.g.:

class A { A frob(); };
class B : A { B frob(); };

But apart from this, forget about it.

Luke


这篇关于是否可以使用返回值重载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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