#include <iostream>
#include <memory>
#include <vector>
#include <algorithm>
using namespace std;
class Base
{
public:
Base() {}
virtual void doStuff() = 0;
};
class DerivedA : public Base
{
private:
//specific A member variables
public:
DerivedA() : Base() {}
virtual void doStuff() {
std::cout << "Derived Class A - Do Stuff" << std::endl;
}
};
class DerivedB : public Base
{
private:
//specific B member variables
public:
DerivedB() : Base() {}
virtual void doStuff() {
std::cout << "Derived Class B - Do Stuff" << std::endl;
}
};
int main() {
// your code goes here
std::vector<std::unique_ptr<Base> > container;
container.push_back(std::make_unique<DerivedA>());
container.push_back(std::make_unique<DerivedB>());
std::for_each(container.begin(), container.end(), [](std::unique_ptr<Base> & b) {
b->doStuff();
});
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWVtb3J5PgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY2xhc3MgQmFzZQp7CnB1YmxpYzoKICAgIEJhc2UoKSB7fQogICAgdmlydHVhbCB2b2lkIGRvU3R1ZmYoKSA9IDA7Cn07CgpjbGFzcyBEZXJpdmVkQSA6IHB1YmxpYyBCYXNlCnsKcHJpdmF0ZToKICAgIC8vc3BlY2lmaWMgQSBtZW1iZXIgdmFyaWFibGVzCnB1YmxpYzoKICAgIERlcml2ZWRBKCkgOiBCYXNlKCkge30KICAgIHZpcnR1YWwgdm9pZCBkb1N0dWZmKCkgewoJCXN0ZDo6Y291dCA8PCAiRGVyaXZlZCBDbGFzcyBBIC0gRG8gU3R1ZmYiIDw8IHN0ZDo6ZW5kbDsKICAgIH0KfTsKCmNsYXNzIERlcml2ZWRCIDogcHVibGljIEJhc2UKewpwcml2YXRlOgogICAgLy9zcGVjaWZpYyBCIG1lbWJlciB2YXJpYWJsZXMKcHVibGljOgogICAgRGVyaXZlZEIoKSA6IEJhc2UoKSB7fQogICAgdmlydHVhbCB2b2lkIGRvU3R1ZmYoKSB7CgkJc3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