V
V
Vitaly Adamsov2020-05-19 11:55:52
OOP
Vitaly Adamsov, 2020-05-19 11:55:52

How does the mechanism of virtual methods work in programming languages ​​and how does it differ from ordinary methods?

How does the mechanism of virtual methods work in programming languages ​​and how does it differ from ordinary methods?

I'm interested in this table, but I can't figure it out properly. Can someone explain in simple terms?

5ec39e72aa8c8195177309.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Robur, 2020-05-19
@adamsoff

If in simple words, then the usual methods lie in memory at a previously known place, and the compiler generates the instruction "call code at address XXX".
The code being called is always the same.
with virtual ones - it depends on the class, so the compiler generates such instructions:
"look at what kind of class obj has, go to the method table of this class, find the address for the ToString function there, and call the code at this address"
for one class, the address will be XXX , and one code will be called, for another class it will be YYY and another code will be called.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question