In C++, there is an entity known as the virtual table. This table is used for runtime (dynamic) function pointers and is required for inheritance.
A virtual table is automatically generated (by the compiler) whenever a class declares a function virtual (any derived class of this base class will also contain a virtual table). Recall, in C++, a function is declared virtual if a derived class is permitted to override it. This virtual table is stored in the program code, and an associated pointer, known as the virtual table pointer (vtptr) is used to dereference the runtime object's function. Often, the virtual table sits above the program code, but below the heap.
The virtual table allows the virtual table pointer to point to the correct function to invoke during runtime. For example, if a base class declares the function overwrite() as virtual, then a virtual table is generated in this class. Any derived class, whether it overrides this function will also contain a virtual table. During runtime, the virtual table pointer points to the current derived class (if the object's pointer is any ancestor's class), and selects the appropriate function. In this example, since the derived class did not override the function, then the virtual table (of the dervied class) will have an entry that references the base class's function instead. On the other hand, if the derived class did override the virtual function, then the virtual table pointer will be pointing to the derived class's function instead.
Always make sure to declare your class's destructor virtual if there is ever a chance of subtyping that base class; otherwise, you risk not invoking the derived class's destructor if the pointer is of base class.
Thanks for the sensible critique. Me and my neighbor were just preparing to do some research on this. We got a grab a book from our local library but I think I learned more clear from this post. I'm very glad to see such wonderful info being shared freely out there.
<a href="http://www.bagmulberry.co.uk/mulberry-handbags-c-9.html" title="mulberry handbags">mulberry handbags</a>
I have recently started a blog, the information you provide on this site has helped me greatly. Thank you for all of your time & work.
[url=http://www.superclassicboots.com/ugg-5825-short-boots-c-21.html]ugg classic short[/url]
<a href="http://www.superclassicboots.com/ugg-5825-short-boots-c-21.html" title="ugg classic short">ugg classic short</a>
Whats up very cool blog!! Man .. Excellent .. Amazing .. I will bookmark your blog and take the feeds also?I am|I'm} glad to seek out so many useful info here within the publish, we need work out extra strategies on this regard, thanks for sharing.
[url=http://howtoloseyourstomachfat.blogspot.com]Lose Stomach Fat Fast[/url]
<a href="http://howtoloseyourstomachfat.blogspot.com" title="Lose Stomach Fat Fast">Lose Stomach Fat Fast</a>
You can definitely see your expertise in the work you write. The sector hopes for even more passionate writers such as you who are not afraid to mention how they believe. All the time go after your heart. "The only way most people recognize their limits is by trespassing on them." by Tom Morris.
<a href="http://pinterest.com/daniel0128/mulberry-bags/" title="mulberry bags">mulberry bags</a>
You are my aspiration , I own few blogs and occasionally run out from to post .
<a href="http://www.cellphonebranded.com/" title="Cell Phone">Cell Phone</a>