首先,我想说我是初学者,我就此问题进行了一些研究
我创建了五个类superbase
,base
和3个派生的:
class superbase
{
QList<base*> listofbase; //Composition relation between super base and base
// some other attributes
public:
superbase(); // or other overloaded constructor
};
class base
{
int i;
public:
base();
};
class derived1 : // Which inheritance should be used with base
{
int j;
public:
derived1(); // or other overloaded constructor
};
class derived2 : // Which inheritance should be used with base
{
int k;
public:
derived2(); // or other overloaded constructor
};
class derived3: // Which inheritance should be used with base
{
int l;
public:
derived3(); // or other overloaded constructor
};
superbase
和base
具有构图关系derived1
,derived2
,derived3
仅从base
继承superbase
我的任务
base
类的多个对象作为superbase
类(QList< base* > listofbase;
)的私有属性。基类的每个对象都可以包含派生类的多个对象(derived1
,derived2
或derived3
)。 问题:
答案 0 :(得分:-1)
使用静态工厂和受保护的构造函数在Base类中实现它。