Hello, I've searched groups and the std unsuccessfully for an explanation
of the following - I'd appreciate any comments you may have.
Given the following diamond multiple inheritance pattern, with the base
class having 2 constructors, only the default constructor is called. Is
there a way to require the other constructor to be used?
First, the output:
Base default constructor
Derived1:
Derived2:
Join:
Main:
class Base
{
public:
Base ()
{ cout << "Base default constructor" << endl; }
Base (string const & useMsg)
: msg (useMsg)
{ cout << "Base: " << msg << endl; }
virtual ~Base() {}
string msg;
};
class Derived1 : virtual public Base
{
public:
Derived1 (string const & useMsg)
: Base (useMsg)
{ cout << "Derived1: " << msg << endl; }
};
class Derived2 : virtual public Base
{
public:
Derived2 ()
: Base ()
{ cout << "Derived2: " << msg << endl; }
};
class Join : public Derived1, public Derived2
{
public:
Join ()
: Derived1 ( string ("Hello") ), Derived2 ()
{ cout << "Join: " << msg << endl; }
};
int main ()
{
Join join;
cout << "Main: " << join.msg << endl;
return 0;
}