Christian Gollwitzer wrote:

You don't need to explain a vtable to explain dynamic_cast. Only if you want to become a compiler writer. It is not even required, vtables are just the most common implementation.

dynamic_cast simply checks if the actual object that the pointer points to is an instance of a derived class, and then casts it into that. You could "explain" it with the following pseudo-code

template <T*, base*>
T* dynamic_cast<T*>(base *input) {
    if (isinstanceof(base, *input)) { return (T*)input; }
    else { return nullptr; }
}

How that works (particularly the "isinstanceof") is not the business of the programmer - it is sufficient to know that the compiler somewhere stores this information for every object.

    Christian

With that, the students would "boo you off the stage!"... and maybe accuse you of being a "know it all". ; ) The point of college is more about teaching students to think rather than in being efficient. I have little doubt that a tech school could "get through everything" much faster.

Bill
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to