У меня есть Geometry
класс
class Geometry
{
public:
std::string stdstrType;
bool bValid;
public:
Geometry()
Geometry( std::string strType , bool bValue )
Geometry(const Geometry &g)
~Geometry()
virtual void draw();
bool isValid();
void setValidState(bool bState);
virtual void Init();
std::string GetName();
};
Какой базовый класс для Geometry
объектов, как в этом случае для Sphere
class
class Sph : public Geometry
{
public:
Sph( float radius , float segments );
~Sph();
void init();
void CleanUp();
void draw();
private:
float fRadius, fSegments;
bool isInited;
unsigned int m_VAO, m_VBO;
int iNumsToDraw;
SumShader shader;
bool isChanged;
};
У меня есть древовидная структура, содержащая различные объекты Container
, а Geometry
- это тип данных в объекте Container
.
class Container
{
private:
std::string stdstrContainerName;
std::string stdstrPluginType;
Geometry Geom;
}
Поскольку каждый элемент дерева может содержать сферу или прямоугольник, поэтому я хотел бы использовать функцию рисования геометрии для рисования типов объектов Geometry
.
Для этого, когда я пытаюсь привести любой Geometry
тип объекта к Geometry
, я получаю сообщение об ошибке.
Sph sphere(0.1 , 32);
Geometry *geom = &sphere;
Container cont("Sphere" , "SPHERE" , *geometry );
myModel->SetContainer(child, cont);
Конструктор для контейнера
Container::Container( std::string strName, std::string strType, const
Geometry& geometry) : Geom(geometry)
{
stdstrContainerName = strName;
stdstrPluginType = strType;
}
void TreeModel::SetContainer(const QModelIndex &index, Container Cont)
{
TreeItem *item = getItem(index);
item->setContainer(Cont);
}
class TreeItem
{
public:
// Functions here
private:
QList<TreeItem*> childItems;
Container itemData;
TreeItem* parentItem;
};
1) Это правильный подход?
2) Как я могу привести Geometry
объекты к указателю Geometry
?