Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class I1
- {
- public:
- virtual void method1() = 0;
- };
- class I2
- {
- public:
- virtual void method2() = 0;
- };
- class A : public I1, public I2
- {
- public:
- int id;
- virtual void method1(){}
- virtual void method2(){}
- };
- class C
- {
- public:
- std::vector<A> vector;
- I1* getI1ById(int id){return &(vector[id]);}
- I2* getI2ById(int id){return &(vector[id]);}
- };
- int main()
- {
- C c;
- A a;
- c.vector.push_back(a);
- //...
- I1* i1 = c.getI1ById(0);
- I2* i2 = c.getI2ById(0);
- a.method1(); // ok
- a.method2(); // ok
- i1->method1(); // ok
- i1->method2(); // error
- i2->method1(); //error
- i2->method2(); //ok
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement