Skip to content

Commit 9dc7885

Browse files
WalterBrightdlang-bot
authored andcommitted
Improve wording of Virtual Functions section
1 parent 32dec24 commit 9dc7885

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

spec/function.dd

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -726,32 +726,27 @@ $(H2 $(LNAME2 property-functions, Property Functions))
726726

727727
$(H2 $(LNAME2 virtual-functions, Virtual Functions))
728728

729-
$(P Virtual functions are functions that are called indirectly through a
730-
function pointer table, called a vtbl[], rather than directly. All
731-
$(D public) and $(D protected) member functions which are non-static and
732-
are not templatized are virtual unless the compiler can determine that
733-
they will never be overridden (e.g. they are marked with $(D final) and
734-
do not override any functions in a base class), in which case, it will
735-
make them non-virtual. Static or `final` functions with `Objective-C`
736-
linkage are virtual as well. This results in fewer bugs caused by not
737-
declaring a function virtual and then overriding it anyway.
729+
$(P Virtual functions are class member functions that are called indirectly through a
730+
function pointer table, called a `vtbl[]`, rather than directly.
738731
)
739732

740-
$(P Member functions which are $(D private) or $(D package) are never
741-
virtual, and hence cannot be overridden.
733+
$(P Member functions that are virtual can be overridden, unless they are `final`.
742734
)
743735

744-
$(P Functions with non-D linkage cannot be virtual and hence cannot be
745-
overridden.
736+
$(P Struct and union member functions are not virtual.
746737
)
747738

748-
$(P Member template functions cannot be virtual and hence cannot be
749-
overridden.
739+
$(P Static member functions are not virtual.
750740
)
751741

752-
$(P Functions marked as $(D final) may not be overridden in a
753-
derived class, unless they are also $(D private).
754-
For example:
742+
$(P Member functions which are $(D private) or $(D package) are not virtual.
743+
)
744+
745+
$(P Member template functions are not virtual.
746+
)
747+
748+
$(P Member functions with `Objective-C` linkage are virtual even if marked
749+
with `final` or `static`.
755750
)
756751

757752
------
@@ -786,10 +781,9 @@ void func()
786781
}
787782
------
788783

789-
$(P Covariant return types
790-
are supported, which means that the
791-
overriding function in a derived class can return a type
792-
that is derived from the type returned by the overridden function:
784+
$(P The overriding function may be covariant with the overridden function.
785+
A covariant function has a type that is implicitly convertible to the
786+
type of the overridden function.
793787
)
794788

795789
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
@@ -811,7 +805,7 @@ class Bar : Foo
811805
)
812806

813807
$(P Virtual functions all have a hidden parameter called the
814-
$(I this) reference, which refers to the class object for which
808+
$(I this) reference, which refers to the class object instance for which
815809
the function is called.
816810
)
817811

@@ -820,7 +814,7 @@ class Bar : Foo
820814
unnamed, parameter which is the selector it was called with.
821815
)
822816

823-
$(P To avoid dynamic binding on member function call, insert
817+
$(P To directly call a base member function, insert
824818
base class name before the member function name. For example:
825819
)
826820

@@ -857,6 +851,12 @@ void main()
857851
------
858852
)
859853

854+
$(IMPLEMENTATION_DEFINED Normally calling a virtual function implies getting the
855+
address of the function at runtime by indexing into the class's `vtbl[]`.
856+
If the implementation can determine that the called virtual function will be statically
857+
known, such as if it is `final`, it can use a direct call instead.
858+
)
859+
860860
$(H3 $(LNAME2 function-inheritance, Function Inheritance and Overriding))
861861

862862
$(P A function in a derived class with the same name and parameter

0 commit comments

Comments
 (0)