class subscriber
{
public:
virtual void update() = 0;
}
class entity : public subsriber
{
public:
virtual void update() = 0;
}
class myObject : public entity
{
public:
virtual void update()
{
do_things();
}
}
subscriber * ptr = new myObject; //will use shared_ptr, but here i want simplicity
ptr->update();
The question is, will the proper update function (the one implemented in myObject) be called? And is it valid to have 2 pure virtual functions with the same name in one “family”?
Yes, it will be called.
The second declaration (i.e. inside the
entityclass) does not introduce a second pure virtual function into the family: the signatures are identical, soupdate()is a single virtual function. Moreover, declaring it for the second time is not necessary:entitywould remain abstract, and would have access to theupdate()method even if you removed the second declaration.