A fixed method cannot run using a certain eg, and it is an assemble-go out mistake to mention to that when you look at the a fixed approach.
A situation means operates with the a given exemplory instance of a category, which such as for example can be accessed because (§11.7.12).
14.6.cuatro Virtual tips
Whenever a case approach statement comes with a virtual modifier, one method is allowed to be an online means. When no digital modifier can be found, the procedure is said become a non-digital approach.
The newest utilization of a non-virtual system is invariant: The brand new execution is the same perhaps the experience invoked with the an exemplory instance of the category where it’s proclaimed otherwise an instance of an excellent derived class. Alternatively, brand new utilization of an online approach are superseded of the derived kinds. The procedure of superseding the fresh new utilization of a hereditary virtual method is called overriding you to approach (§14.6.5).
In the a non-virtual strategy invocation, the brand new amass-go out brand of this new such as is the deciding factor
When you look at the a virtual strategy invocation, the newest focus on-date brand of the fresh new for example for which you to definitely invocation occurs identifies the genuine strategy implementation so you’re able to invoke. When you look at the real conditions, when a method titled Letter is actually invoked which have a disagreement number Good to your a situation having a gather-time particular C and you can a race-date variety of Roentgen (where Roentgen was possibly C or a class derived from C ), the latest invocation is processed below:
- At the binding-time, overburden solution is placed on C , N , and you can Good , to choose a specific means Meters regarding the number of actions proclaimed during the and you will inherited because of the C . This might be described when you look at the §11.eight.8.2.
- Next in the manage-time:
- When the Yards try a low-digital method, Meters is actually invoked.
- If you don’t, Meters is an online approach, in addition to most derived utilization of Meters with regards to Roentgen was invoked.
For every single digital strategy proclaimed from inside the or passed on from the a class, there is certainly a the majority of derived utilization of the method in respect to this category. More derived implementation of an online approach Meters in respect in order to a class Roentgen is decided below:
- When the R contains the releasing virtual declaration from Meters , after that this is the extremely derived utilization of M with respect in order to R .
- Otherwise, in the event the R include an enthusiastic bypass regarding M , after that this is basically the extremely derived utilization of Meters with respect to R .
- Or even, one particular derived implementation of M when it comes to R is actually the same as one particular derived implementation of Meters with respect toward head ft family of R .
In the analogy, A beneficial raises a low-virtual method F and you will a virtual means Grams . The course B brings up a different low-digital method F , thus covering up brand new passed down F , and just have overrides the brand new inherited strategy G . The brand new example produces new output:
Note that the latest declaration a good.G() invokes B.Grams , perhaps not A.Grams . It is because the latest work on-day types of the instance (that’s B ), perhaps not the new attain-day sorts of the newest for example (that’s A great ), identifies the true means implementation so you can invoke. avoid analogy
While the tips can hide inherited steps, it is possible to possess a course so you’re able to have several virtual strategies with similar signature. This doesn’t expose an ambiguity disease, once the all but one particular derived method is actually hidden.
the C and D groups include two virtual steps into same signature: One delivered from the An excellent together with one to produced of the C . wyszukiwanie sugardaddie The method put by the C covers the procedure passed down regarding A . Therefore, this new override report when you look at the D overrides the procedure put from the C , and is not possible for D so you can bypass the process introduced because of the Good . The fresh analogy produces the fresh new efficiency:
Keep in mind that it is possible to invoke the undetectable digital method by the accessing an instance of D as a result of a less derived variety of where the method is not invisible. stop analogy