On the caller side, I want to pass arbitrary objects of a specific super class via stream operator:
class SubclassA : public Superclass { ... }
class SubclassB : public Superclass { ... }
...
Container container;
container << SubclassA(param1, param2) << SubclassB(param);
On the callee side, I have to store all passed objects in a vector or list:
std::vector<std::unique_ptr<Superclass>> childs;
Container & operator<<(Superclass const & child) {
childs.emplace_back(new Superclass(child)); // not possible, since Superclass is abstract
return *this;
}
Are there any possibilities to keep the desired behaviour on the callee side, avoiding the need of std::unique_ptr
or new
keyword?
Edit:
Add missing &
in stream operator parameter.