Ada Reference Manual (Ada 2022)
8.3.1 Overriding Indicators
An overriding_indicator is used to declare that an operation is intended to override (or not override) an inherited operation.
Syntax
overriding_indicator ::= [not] overriding
Legality Rules
If an abstract_subprogram_declaration, null_procedure_declaration, expression_function_declaration, subprogram_body, subprogram_body_stub, subprogram_renaming_declaration, generic_instantiation of a subprogram, or subprogram_declaration other than a protected subprogram has an overriding_indicator, then:
- the operation shall be a primitive operation for some type;
- if the overriding_indicator is overriding, then the operation shall override a homograph at the place of the declaration or body;
- if the overriding_indicator is not overriding, then the operation shall not override any homograph (at any place).
In addition to the places where Legality Rules normally apply, these rules also apply in the private part of an instance of a generic unit.
NOTE Rules for overriding_indicators of task and protected entries and of protected subprograms are found in 9.5.2 and 9.4, respectively.
Examples
Example of use of an overriding indicator when declaring a security queue derived from the Queue interface of 3.9.4:
type Security_Queue is new Queue with record ...;
overriding
procedure Append(Q : in out Security_Queue; Person : in Person_Name);
procedure Append(Q : in out Security_Queue; Person : in Person_Name);
overriding
procedure Remove_First(Q : in out Security_Queue; Person : out Person_Name);
procedure Remove_First(Q : in out Security_Queue; Person : out Person_Name);
overriding
function Cur_Count(Q : in Security_Queue) return Natural;
function Cur_Count(Q : in Security_Queue) return Natural;
overriding
function Max_Count(Q : in Security_Queue) return Natural;
function Max_Count(Q : in Security_Queue) return Natural;
not overriding
procedure Arrest(Q : in out Security_Queue; Person : in Person_Name);
procedure Arrest(Q : in out Security_Queue; Person : in Person_Name);
The first four subprogram declarations guarantee that these subprograms will override the four subprograms inherited from the Queue interface. A misspelling in one of these subprograms will be detected at compile time by the implementation. Conversely, the declaration of Arrest guarantees that this is a new operation.