Как я могу вызвать производную функцию из базового класса? Я имею в виду возможность заменить одну функцию из базового в производный класс.
Ex.
class a
{
public:
void f1();
void f2();
};
void a::f1()
{
this->f2();
}
/* here goes the a::f2() definition, etc */
class b : public a
{
public:
void f2();
};
/* here goes the b::f2() definition, etc */
void lala(int s)
{
a *o; // I want this to be class 'a' in this specific example
switch(s)
{
case 0: // type b
o = new b();
break;
case 1: // type c
o = new c(); // y'a know, ...
break;
}
o->f1(); // I want this f1 to call f2 on the derived class
}
Может быть, я ошибаюсь. Любые комментарии о различных дизайнах также приветствуются.