I've been told to make my class abstract:
public abstract class Airplane_Abstract
And to make a method called move virtual
public virtual void Move() { //use the property to ensure that there is a valid position object double radians = PlanePosition.Direction * (Math.PI / 180.0); // change the x location by the x vector of the speed PlanePosition.X_Coordinate += (int)(PlanePosition.Speed * Math.Cos(radians)); // change the y location by the y vector of the speed PlanePosition.Y_Coordinate += (int)(PlanePosition.Speed * Math.Sin(radians)); }
And that 4 other methods should be "pure virtual methods." What is that exactly?
They all look like this right now:
public virtual void TurnRight() { // turn right relative to the airplane if (PlanePosition.Direction >= 0 && PlanePosition.Direction < Position.MAX_COMPASS_DIRECTION) PlanePosition.Direction += 1; else PlanePosition.Direction = Position.MIN_COMPASS_DIRECTION; //due north }
A pure virtual function is a function that must be overridden in a derived class and need not be defined. A virtual function is declared to be “pure” using the curious =0 syntax. For example: class Base {
C# virtual method is a method that can be redefined in derived classes. In C#, a virtual method has an implementation in a base class as well as derived the class. It is used when a method's basic functionality is the same but sometimes more functionality is needed in the derived class.
A virtual function is a member function of base class which can be redefined by derived class. A pure virtual function is a member function of base class whose only declaration is provided in base class and should be defined in derived class otherwise derived class also becomes abstract.
A pure virtual function is declared by assigning 0 in declaration. See the following example.
My guess is that whoever told you to write a "pure virtual" method was a C++ programmer rather than a C# programmer... but the equivalent is an abstract method:
public abstract void TurnRight();
That forces concrete subclasses to override TurnRight
with a real implementation.
"Pure virtual" is C++ terminology. The C# equivalent is an abstract method.
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