overriding

overriding abstract generic method from non generic class

瘦欲@ 提交于 2019-12-10 13:28:44
问题 base class class Drawer { public abstract void Draw<T>(T type); } derived class #1 class ADrawer : Drawer { public override void Draw<T>(List<T> list) { foreach (var a in list) { DrawA(a); } } public void DrawA(Agent a) { //draw code here } } derived class #2 class AnotherDrawer : Drawer { public override void Draw<T>(T number) { if (number == 1) { //draw code } } } The error is in the #1 derived class : "no suitable method found to override" Should I be using 'virtual' in the base class as

C# Override with different parameters?

痞子三分冷 提交于 2019-12-10 13:26:28
问题 Here is an example of what I am looking to do. public class A { public virtual void DoSomething(string a) { // perform something } } public class B : A { public Override void DoSomething(string a, string b) { // perform something slightly different using both strings } } So I want to override DoSomething from class A and allow it to pass a second parameter. Is this possible? 回答1: When overriding a virtual method, you must keep the original "contract" of the method, which in your case is a

Virtual functions overriding and hiding

心不动则不痛 提交于 2019-12-10 13:23:05
问题 I have this code : class Event{}; class CustomEvent:public Event{}; class Handler { public: virtual void inform(Event e ){} }; class CustomHandler : public Handler { public: void inform(CustomEvent e){} }; CustomEvent cEvent; Handler* handler = new CustomHandler; //this calls Handler::inform(Event), not CustomHandler::(CustomEvent) , as I expected handler->inform(cEvent); If I change the code to this : class Handler { public: virtual void inform(Event e ){} virtual void inform(CustomEvent e){

Is there a way to flag (at compile time) “overridden” methods whose signatures don't match base signature?

偶尔善良 提交于 2019-12-10 13:19:28
问题 Basically, I want the C# compiler functionality of its override keyword in my C++ code. class Base { virtual int foo(int) const; }; class Derived : public Base { virtual int foo(int); // wanted to override Base, but forgot to declare it const }; As we all know, the above code will compile fine, but yield some strange runtime behavior. I would love my C++ compiler to catch my poor implementation with something like C#'s override keyword. Are there any keywords like "override" being introduced

In python - the operator which a set uses for test if an object is in the set

女生的网名这么多〃 提交于 2019-12-10 12:39:32
问题 If I have a list of objects, I can use the __cmp__ method to override objects are compared. This affects how the == operator works, and the item in list function. However, it doesn't seem to affect the item in set function - I'm wondering how I can change the MyClass object so that I can override the behaviour how the set compares items. For example, I would like to create an object that returns True in the three print statements at the bottom. At the moment, the last print statement returns

Why is can't use overriding method in C#? (not about keyword)

隐身守侯 提交于 2019-12-10 12:07:48
问题 public abstract class A { public void CallMe() { Console.WriteLine("I am A."); } } public class B : A { new public void CallMe() { Console.WriteLine("I am B."); } } class Program { static void Main(string[] args) { A a = new B(); a.CallMe(); } } output is "I am A." Why this happening? Is this reasonable? compiled by Visual Studio 2012. 回答1: You need to make the CallMe() method in your base class virtual and then use the override modifier in B : public abstract class A { public virtual void

C# class using subclass does not implement inherited abstract member error

回眸只為那壹抹淺笑 提交于 2019-12-10 11:30:00
问题 Here's the c# code I'm trying to compile Fairly simple, testDMO that inherits from testDMOBase Then test that inherits from testBase public abstract class testDMOBase { } public class testDMO : testDMOBase { } public abstract class testBase { abstract protected void LoadCRUD(testDMOBase dmo); } public class test : testBase { override protected void LoadCRUD(testDMO dmo) { } } I'm getting the following errors: 'test' does not implement inherited abstract member 'testBase.LoadCRUD(testDMOBase)'

C# - Overriding an Event Handler - Adding a parameter

假装没事ソ 提交于 2019-12-10 11:25:41
问题 I'm using the System.Diagnostics.Process class to execute a command line program. I am using the OutputDataReceived method to redirect the output to my own method. pr.OutputDataReceived += new DataReceivedEventHandler(OnDataReceived); pr.ErrorDataReceived += new DataReceivedEventHandler(OnDataReceived); However, I have multiple Threads running multiple instances of this cmd program. What I want to do is to be able to identify which process instance the output data came from - ideally, a

GWT Customize CellList Multi-Selection Model for Mobile Devices

坚强是说给别人听的谎言 提交于 2019-12-10 11:08:26
问题 I have an application, that uses the MultiSelectionModel, and it works great, but I need the site I'm developing to work on mobile devices, and so I can't use the keyboard to assist in selecting the elements (since it doesn't exist). EX: On the desktop I just hold ctrl and click on all the element that I want to select. So on the mobile device, I would like to modify the default behavior of the MultiSelectionModel so that when you click on a CellList item, it toggles the selection state of

Overriding alternative to cherry-pick

a 夏天 提交于 2019-12-10 10:58:15
问题 There is a cherry-pick command in the git which allows me to copy some commit on top of the current. However, it does some conflict resolution, that I do not care about. What is alternative to cherry-pick which just copies picked commit over on top of current commit? I can do it manually: select desired commit, copy its files, save them into non-managed folder, select current commit which will be the base for new one, copy the archived files into the git working folder. Separately, I have to