C++ 运行错误 问题
#include <iostream.h>class Base1
{
int b1;
public:
Base1 (int i)
{
b1 = i;
cout << "Constructor Base1." << endl;
}
~Base1 ()
{
cout << "Destructor Base1." << endl;
}
void Print ()
{
cout << b1 << '\t';
}
};
class Base2
{
int b2;
public:
Base2 (int i)
{
b2 = i;
cout << "Constructor Base2." << endl;
}
~Base2 ()
{
cout << "Destructor Base2." << endl;
}
void Print ()
{
cout << b2 << '\t';
}
};
class Base3 :public Base2
{
int b3;
public:
Base3 (int i, int j) : Base2 (i)
{
b3 = j;
cout << "Constructor Base3." << endl;
}
~Base3 ()
{
cout << "Destructor Base3." << endl;
}
void Print ()
{
Base2:: Print ();
cout << b3 << '\t';
}
class Base4
{
int b4;
public:
Base4 ()
{
b4 = 0;
cout << "Constructor Base4." << endl;
}
~Base4 ()
{
cout << "Destructor Base4." << endl;
}
void Print ()
{
cout << b4 << '\t';
}
};
};
class Member
{
int m;
public:
Member (int i)
{
m = i;
cout << "Constructor Member." << endl;
}
~Member ()
{
cout << "Destructor Member." << endl;
}
int GetM ()
{
return m;
}
};
class Derived :public Base3, public Base1, public Base4
{
int d;
Member mem;
public:
Derived (int i, int j, int k, int l, int q);
~Derived ();
void Print ();
};
Derived:: Derived (int i, int j, int k, int l, int q) : Base1 (i) , Base3 (j, k), mem (l)
{
d = q;
cout << "Constructor Derived." << endl;
}
Derived:: ~Derived ()
{
cout << "Destructor Derived." << endl;
}
void Derived:: Print ()
{
Base4:: Print ();
Base1:: Print ();
Base3:: Print ();
cout << mem.GetM () << '\t';
cout << d << endl;
}
void main (void)
{
Derived obj (1, 2, 3, 4, 5);
obj.Print ();
}