方法覆盖和重载 [英] methods overriding and overloading

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

问题描述

我可以重载或覆盖方法只是使用不同的返回值?

  class A {

virtual int Foo(); //这个场景可能有/没有关键字virtual
}

class B:public A {
virtual double Foo();
}

A * Base = new B();
int i = Base-> Foo(); //将这只是将double转换为int?

并关于重载:

  class A {

virtual int Foo();
virtual float Foo(); // 这可能吗 ?

int Goo();
float Goo(); //或者这个?
}

B类{
double Foo();
}

感谢

解决方案

函数的返回类型不是其签名的一部分,因此不能重载。


can i overload or override methods just by using different return value ? is virtual matter in thie case ?

for example :

class A{

  virtual int Foo(); // is this scenario possible with/without the keyword virtual
}

class B : public A {
   virtual double Foo();
}

A* Base = new B();
int i = Base->Foo(); // will this just convert double to int ?

and regarding overloading :

class A{

  virtual int Foo(); 
  virtual float Foo(); // is this possible ?

  int Goo();
  float Goo(); // or maybe this ?
}

Class B{
    double Foo();
}

thanks

解决方案

The return type of a function is not part of its signature, thus it can't be overloaded.

这篇关于方法覆盖和重载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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