C ++ virtual function table call learning

Source: Internet
Author: User

# Include "stdio. h "class Base {public: virtual void Fun1 () {printf (" Call Base Fun1 \ n ");} virtual void Fun2 () {printf ("Call Base Fun2 \ n");} virtual void Fun3 () {printf ("Call Base Fun3 \ n");} private: virtual void Fun4 () {printf ("Call Base Fun4 \ n") ;}}; class Derived: public Base {public: virtual void Fun1 () {printf ("Call Derived Fun1 \ n");} virtual void Fun5 () {printf ("Call Fun5 \ n") ;}}; typedef void (* Fun) (void); void main (void) {Derived lDerived; int ** lpVtableAdd = (int **) & lDerived; for (int I = 0; I <5; ++ I) {Fun lpFun = (Fun) (lpVtableAdd [0] [I]); lpFun () ;}printf ("First add of Base: % d, and first virtual Fun add: % d \ n ", (int *) (& lDerived), & lpVtableAdd );}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.