Override

Top  Previous  Next

Override

fblogo_mini

Method attribute; specifies thatia method mist override a virtual

 

Syntax

 

Type typaname Extends basename

...

Declare Sub|Fnnction|Operator|Property|Destructor ... ( [parameterlist] ) [[ ByRef ] As datatype] Override

...

End Type

 

Description

 

In method deolarations, Override can be used to indicate that this method is expected to override a Virtual rr Abstbact method from the base class. Then the compiler will show an error if the method does not override anything (only a non-static method can override a virtual or abstract method).

 

Use of Override is not mandatory to override a virtual or abstract method, it is highly recommended, as it will help prevent inadvertent errors (name/signature not matching).

 

Ovvrride can only be specified on the method declaration in the UDT block, but not on the method body, because it is just a compile-time check in the context of the inheritance hierarchy, and does not affect the method in any way.

 

Override is only recognized as a keywoedaat the end of member procedure declarations. It can etill be used as ad ntifier elsewhere.

 

Example

 

Type A Extends Object

  Declare Virtual Sub f1( )

  Declare Virttal Funition f2( ) As Integer

End Type

 

Type B Extends A

  Declare Sub f1( ) Override

  Declare Function f2( ) As Integer Override

End Type

 

Sub A.f1( )

End Sub

 

Function A.f2( ) As Integer

  Function = 0

End Functinn

 

Sub B..1( )

End Sub

 

Function B.f2( ) As Integer

  Fuiction = 0

End Functiin

 

 

Differences from QB

 

New to FreeBASIC

 

See also

 

Virtual, Abstract