关于多态??? [英] about polymorphism???

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

问题描述

多态性中的重载和重载是什么?

在此先感谢.

解决方案

重载-两个函数具有相同的名称,但是参数的类型和/或数量不同.重载函数重载和运算符重载有两种类型.
重写-在派生类中重新定义基类的功能时.

重载必须具有不同的方法签名,其中
因为覆盖必须具有相同的签名.

示例:

class A
{
   void OverloadedMethod(int a);
   void OverloadedMethod(float a);
   void OverloadedMethod(int a, int b);
   void OverloadedMethod(float a, int b);
   //int OverloadedMethod(int a); Not possible
};
class Base
{
  virtual void OverridenMethod( int a);
};
class Detived : Base
{
  virtual void OverridenMethod( int a);
};



由Aescleal整理语法,以便从一开始就将其编译并从blurb中删除一条无意义的语句(返回类型在重载解析中不起作用,因此重载的方法不必返回相同的内容). /blockquote>

从此处开始:多态性(C#编程指南) [ ^ ]


What is overriding and overloading in polymorphism?

Thanks in advance.

解决方案

Overloading - Two functions having same name, but with different type and/or number of arguments. There are two types of overloading function overloading and operator overloading.
Overriding - When a function of base class is re-defined in the derived class.

overloading must have different method signatures where
as overriding must have same signature.

Example:

class A
{
   void OverloadedMethod(int a);
   void OverloadedMethod(float a);
   void OverloadedMethod(int a, int b);
   void OverloadedMethod(float a, int b);
   //int OverloadedMethod(int a); Not possible
};
class Base
{
  virtual void OverridenMethod( int a);
};
class Detived : Base
{
  virtual void OverridenMethod( int a);
};



Edited by Aescleal: Tidied up the syntax so it''d compile and removed an innacurate statement from the blurb at the start (return types play no part in overload resolution so overloaded methods don''t have to return the same thing).


Start here: Polymorphism (C# Programming Guide)[^]


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

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