how are virtual tables stored in memory? their layout?
e.g.
class A{
public:
virtual void doSomeWork();
};
class B : public A{
public:
As others already wrote, there is no general approach. (Heck, nobody even mandates that virtual tables are used at all.)
However, I believe they are most likely implemented as a hidden pointer at a certain offset in the object which references a table of function pointers. Certain virtual functions' addresses occupy certain offsets in that table. Usually there's also a pointer to the dynamic type's std::type_info
object.
If you're interested in things like this, read Lippmann's "Inside the C++ Object Model". However, unless your interest is academic (or you're trying to write a C++ compiler -- but then you shouldn't need to ask), you shouldn't bother. It's an implementation detail you don't need to know and should never rely on.