Hi.
I would like to know the best way to initialize a constructor in a virtual base base. For example,
Code:
// Base class
class Base()
{
public:
A(int i = 0);
virtual void printA() const = 0;
};
// Derived classes
class X() : public virtual Base
{
public:
X(char a, int j);
virtual void printA();
};
X::X(char a, int j)
{
char temp = a;
A::A(j);
}
class Y() : public virtual Base
{
public:
Y(long x, int k);
virtual void printA();
};
Y::Y(long x, int k)
{
long temp = x;
A::A(k);
}
// Next level down in hierarchy
class Z(); public X, public Y
{
public:
Z(...?...); // What data do I need here to construct X, Y, and Base?
void printA() const;
...
};
Z::Z(...?...)
{
// Do you contruct class X, Y, or Base first?
}
// Implementation
Z example(...?...); // You need to construct Base first.
I know the question is very basic to polymorphic C++ programming. Nonetheless, it is something that want really want to understand.
Thanks,
Kuphryn