Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. MyBaseClass* a = new MyBaseclass();
  2. a->BaseMethod(); // Call method using -> operator (dereference and call)
  3.  
  4. MyBaseClass* b = new MyDerivedClass();
  5. b->DerivedMethod(); // Error: MyBaseClass has no such method
  6.  
  7. // Proper C++-Style casting.
  8. MyDerivedClass* c = dynamic_cast<MyDerivedClass*>(b);
  9. // Shortcut to the above, does not do the type test.
  10. // MyDerivedClass* c = (MyDerivedClass*)b;
  11. c->DerivedMethod(); // Ok
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement