The method call is explicit and implicit . How do they differ? If I understand correctly, explicit it is something like:
obj.meth(x, y); What then is not an obvious challenge? And what methods can not be called explicitly?
The method call is explicit and implicit . How do they differ? If I understand correctly, explicit it is something like:
obj.meth(x, y); What then is not an obvious challenge? And what methods can not be called explicitly?
Here's an example: in PHP, there is a __toString magic method, implementing this method in a class, we specify how an instance of the class should present itself as a string. When an object of a class with a specific __toString method is called in a context that assumes that the work goes with a string, the magic method __toString is implicitly called before performing other actions on the object.
class SomeClass { public function __toString() { return 'Hello World!'; } } $a = new SomeClass(); echo $a; // outputs 'Hello World!' In line with echo $a; at first, the SomeClass::__toString() method will be called implicitly, although we did not explicitly give such instructions, and then echo will be executed.
There are many more examples from different languages, but I think the basic idea should be clear.
UPD
Explicit method call - sorry for taftology, you clearly indicate in your code which method and with what arguments you want to call. An implicit call — the compiler (or interpreter) does it implicitly for you. In C ++, I haven’t written anything for a long time, so unfortunately I can’t give an example of an implicit method call, but I remembered, probably the most well-known and easy-to-understand example of the “implicit” in C ++ is this , a pointer to an instance of a class, all member functions of a class in C ++ (except static) implicitly takes as an argument a pointer to an instance of the class in the context of which the method is accessed.
Source: https://ru.stackoverflow.com/questions/532115/
All Articles