@@ -726,32 +726,27 @@ $(H2 $(LNAME2 property-functions, Property Functions))
726
726
727
727
$(H2 $(LNAME2 virtual-functions, Virtual Functions))
728
728
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.
738
731
)
739
732
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`.
742
734
)
743
735
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.
746
737
)
747
738
748
- $(P Member template functions cannot be virtual and hence cannot be
749
- overridden.
739
+ $(P Static member functions are not virtual.
750
740
)
751
741
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`.
755
750
)
756
751
757
752
------
@@ -786,10 +781,9 @@ void func()
786
781
}
787
782
------
788
783
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.
793
787
)
794
788
795
789
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
@@ -811,7 +805,7 @@ class Bar : Foo
811
805
)
812
806
813
807
$(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
815
809
the function is called.
816
810
)
817
811
@@ -820,7 +814,7 @@ class Bar : Foo
820
814
unnamed, parameter which is the selector it was called with.
821
815
)
822
816
823
- $(P To avoid dynamic binding on member function call , insert
817
+ $(P To directly call a base member function, insert
824
818
base class name before the member function name. For example:
825
819
)
826
820
@@ -857,6 +851,12 @@ void main()
857
851
------
858
852
)
859
853
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
+
860
860
$(H3 $(LNAME2 function-inheritance, Function Inheritance and Overriding))
861
861
862
862
$(P A function in a derived class with the same name and parameter
0 commit comments