#include <iostream>
#include <cstdlib>
using namespace std;
struct IGetA
{
virtual int getA() = 0;
};
class Base : public IGetA
{
protected:
int a;
public:
int getA()
{
return a;
}
};
class Derived : public Base
{
protected:
int b;
};
class Set
{
protected:
IGetA* dataArray;
public:
void run1()
{
int c = 5;
dataArray = new Derived[c];
cout << dataArray[3].getA(); // case 1
}
};
void run2(IGetA* b, int index )
{
cout << b[index].getA();
}
int main()
{
Set set1;
set1.run1();//case 1
Derived set2[5];
run2(set2, 3);// case 2
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGxpYj4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJ1Y3QgSUdldEEKewogICAgdmlydHVhbCBpbnQgZ2V0QSgpID0gMDsKfTsKCmNsYXNzIEJhc2UgOiBwdWJsaWMgSUdldEEKewpwcm90ZWN0ZWQ6CiAgICBpbnQgYTsKcHVibGljOgogICAgaW50IGdldEEoKQogICAgewogICAgICAgIHJldHVybiBhOwogICAgfQp9OwoKY2xhc3MgRGVyaXZlZCA6IHB1YmxpYyBCYXNlCnsKcHJvdGVjdGVkOgogICAgaW50IGI7Cn07CgpjbGFzcyBTZXQKewpwcm90ZWN0ZWQ6CiAgICBJR2V0QSogZGF0YUFycmF5OwpwdWJsaWM6CiAgICB2b2lkIHJ1bjEoKQogICAgewogICAgICAgIGludCBjID0gNTsKICAgICAgICBkYXRhQXJyYXkgPSBuZXcgRGVyaXZlZFtjXTsKICAgICAgICBjb3V0IDw8IGRhdGFBcnJheVszXS5nZXRBKCk7IC8vIGNhc2UgMQogICAgfQp9OwoKdm9pZCBydW4yKElHZXRBKiBiLCBpbnQgaW5kZXggKQp7CiAgICBjb3V0IDw8IGJbaW5kZXhdLmdldEEoKTsKfQoKaW50IG1haW4oKQp7CiAgICBTZXQgc2V0MTsKICAgIHNldDEucnVuMSgpOy8vY2FzZSAxCgogICAgRGVyaXZlZCBzZXQyWzVdOwogICAgcnVuMihzZXQyLCAzKTsvLyBjYXNlIDIKCiAgICByZXR1cm4gMDsKfQ==