For the following code,
class A
{
private:
virtual void f() = 0;
virtual void g() = 0;
...
public:
A()
{
}
...
}
class B : public A
{
private:
void f()
{
...
}
void g()
{
...
}
void h()
{
if (...)
{
f();
}
else
{
g();
}
}
...
public:
B()
{
h();
}
...
}
class C : public A
{
private:
void f()
{
...
}
void g()
{
f();
}
void h()
{
if (...)
{
f();
}
else
{
g();
}
}
...
public:
C()
{
h();
}
...
}
is there a way to avoid repetition of h() (the context of function h() in both classes B and C is the same) or we cannot avoid it simply because we cannot call pure virtual functions in constructors?