Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. struct Context {
  2.     virtual ~Context() = default;
  3. };
  4. struct VideoContext : public Context {};
  5. struct AudioContext : public Context {};
  6.  
  7. struct VideoContextA1 : public VideoContext {
  8.     int mA;
  9.     float mB;
  10. };
  11.  
  12. struct VideoContextA2 : public VideoContext {
  13.     int mC;
  14.     float mD;
  15. };
  16.  
  17. class A {
  18.     virutal int foo(Context* context) = 0;
  19. };
  20.  
  21. class A1 : public A {
  22.     int foo(Context* context) override {
  23.         // dynamic cast
  24.         auto* ctx = dynamic_cast<VideoContextA1*>(context);
  25.         // .... bla bla bla
  26.     }
  27. };
  28.  
  29. class A2 : public A {
  30.     int foo(Context* context) override {
  31.         // dynamic cast
  32.         auto* ctx = dynamic_cast<VideoContextA2*>(context);
  33.         // .... bla bla bla
  34.     }
  35. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement