新和覆盖之间的区别? [英] Difference between new and override?

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

问题描述

我有我想为所有的继承类方法的一些'基地'功能的基类

I have a base class which I want to provide some 'base' functionality for methods for all inheriting classes.

在我的继承类我想做的事:

In my inheriting classes I want to do:

public override void Setup()
{
   base.Setup();
}



但此刻它说我必须使用new关键字。

But at the moment it says I have to use the new keyword.

如何到我,所以我必须使用覆盖关键字?

How to I have it so I have to use the override keyword?

有与当前正在使用的关键字,并使用覆盖它是如何与我有什么区别?

Is there any difference between how it is currently with me using the new keyword and using override?

推荐答案

这是这么说的,因为你没有声明的基方法虚拟 。一旦你这样做,基虚拟 /派生覆盖对关键字才有意义。眼下,编译器抱怨,你不能覆盖非 - 虚拟

It says so because you have not declared the base method virtual. Once you do so, the base virtual/derived override pair of keywords will make sense. Right now, the compiler is complaining that you cannot override a non-virtual method.

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

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