code_junkie

If classes with virtual functions are implemented with vtables, how is a class with no virtual functions implemented?

Nov 11th, 2011
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. struct A
  2. {
  3. void foo ();
  4. void bar () const;
  5. };
  6.  
  7. struct A
  8. {
  9. };
  10.  
  11. void foo (A * this);
  12. void bar (A const * this);
  13.  
  14. struct A
  15. {
  16. virtual void foo ();
  17. };
  18.  
  19. void foo (A * this) {
  20. void (*realFoo)(A *) = lookupVtable (this->vtable, "foo");
  21. (realFoo)(this); // Make the call to the most derived version of 'foo'
  22. }
  23.  
  24. void CMyThingy::DoSomething(int arg);
  25. {
  26. // do something
  27. }
  28.  
  29. void CMyThingy_DoSomething(CMyThingy* this, int arg)
  30. {
  31. /do something
  32. }
  33.  
  34. myObj.doSomething(aValue);
  35.  
  36. CMyThingy_DoSomething(&myObj, aValue);
Add Comment
Please, Sign In to add comment