Advertisement
Guest User

Untitled

a guest
Sep 19th, 2014
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. struct Base
  2. { virtual void foo(); };
  3.  
  4. struct D1 : Base
  5. { virtual void foo(); };
  6.  
  7. struct D2 : D1
  8. { void foo(); };
  9.  
  10. D2 instance;
  11. D1* d1ptr = &instance;
  12. Base* baseptr = &instance;
  13.  
  14. //normal function call to "D2::foo()", no dynamic dispatch.
  15. instance.foo();
  16. //virtual function call to "D2::foo()", one dynamic dispatch.
  17. d1ptr.foo();
  18. //virtual function call to "D2::foo()", does this incur additional
  19. //..overhead compared to "d1ptr.foo()"?
  20. baseptr.foo();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement