I'm having class, that contains few overloaded versions of one method. Every version takes one parameter - object - that object is always derived from one base class. (There is not method taking Base class parameter).
class Base { ... }
class Object1 : public Base { ... }
class Object2 : public Base { ... }
class Object3 : public Base { ... }
class T
{
// ...
do_sth(const Object1& obj);
do_sth(const Object2& obj);
do_sth(const Object3& obj);
// ...
}
Then I create vector with unique_ptr
pointing to Base
class, containing (only) derived class object.
std::vector<std::unique_ptr<Base>> vect; // then some push_backs
Now I want to call T::do_sth
for every object in vect
, like this:
for (auto& object : vect)
T_obj.do_sth(*object);
However, that way it's imposible, because render(*object)
calls do_sth(Base)
, that doesn't even exist (and that wouldn't be wanted behaviour). I tried to replace that line with several different (using casting), but none of my attempts succeeded. How to fix that?