Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. class I1
  2. {
  3. public:
  4.     virtual void method1() = 0;
  5. };
  6.  
  7. class I2
  8. {
  9. public:
  10.     virtual void method2() = 0;
  11. };
  12.  
  13. class A : public I1, public I2
  14. {
  15. public:
  16.     int id;
  17.     virtual void method1(){}
  18.     virtual void method2(){}
  19. };
  20.  
  21. class C
  22. {
  23. public:
  24.     std::vector<A> vector;
  25.    
  26.     I1* getI1ById(int id){return &(vector[id]);}
  27.     I2* getI2ById(int id){return &(vector[id]);}
  28. };
  29.  
  30. int main()
  31. {
  32.     C c;
  33.     A a;
  34.    
  35.     c.vector.push_back(a);
  36.     //...
  37.    
  38.     I1* i1 = c.getI1ById(0);
  39.     I2* i2 = c.getI2ById(0);
  40.    
  41.     a.method1(); // ok
  42.     a.method2(); // ok
  43.    
  44.     i1->method1(); // ok
  45.     i1->method2(); // error
  46.    
  47.     i2->method1(); //error
  48.     i2->method2(); //ok
  49.    
  50.   return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement