The virtual function mechanism works on two things. Virtual Table (VTable) and Virtual Table Pointer (VPtr). To know how they works, you should know their purpose. The VTable serves as a list of address of all the virtual functions in the class. And VPtr is the pointer to the VTable of the class. Using these two, the dynamic linking of the function is done. i.e. the actual function call address is decided/resolved at the run time.
When you declare any function in class as virtual, the function address goes as an entry to virtual table. Every class has got it's own vtable and vptr (virtual pointer).
There are so many things for you to know about Virtual Functions. I've explained the things considering you're new to virtual concepts.
Better you can google out for these stuffs. For now you can have a look at
this[
^].