I'm having trouble overriding the method of a parent class in C#. The parent class is setup like so:
public class Base { public Base(Game1 game) { this.game = game; } public virtual void Draw() { } }
...And the child class:
public class Ext : Base { public Ext(Game1 game) : base(game) { } public override void Draw(SpriteBatch batch) { } }
I know I've successfully overridden a parent method in the past, and right now I'm probably overlooking something incredibly simple... what is it?
EDIT: That was actually a typo: in the actual script, Ext does derive from Base. The problem still persists. Thanks for the quick answers, though. :)
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr. Stroustroupe.
C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.
%d is used to print decimal(integer) number ,while %c is used to print character . If you try to print a character with %d format the computer will print the ASCII code of the character.
Your code as given (after the edit) compiles fine, so something else is wrong that isn't in what you posted.
Some things to check, is everything public? That includes both the class and the method.
Overload with different parameters?
Are you sure that Base
is the class you think it is? I.e. is there another class by the same name that it's actually referencing?
Edit:
To answer the question in your comment, you can't override a method with different parameters, nor is there a need to. You can create a new method (with the new parameter) without the override
keyword and it will work just fine.
If your intention is to prohibit calling of the base method without the parameter you can mark the method as protected
instead of public
. That way it can only be called from classes that inherit from Base
You're not inheriting from your base class:
public class Ext : Base { // constructor public override void Draw() { } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With