I have a list of pointers that can be from diferent derived classes of BaseClass. I want to duplicate some items who's indexes are in m_listEntities_selected (a list of type int). newPosition() is a virtual member. Can I cast 'entity', since I don't know the type of the item at the specified position?
for(int i=0;i<m_listEntities_selected.size();i++)
{
BaseClass *entity = new BaseClass;
entity = dynamic_cast< typeid (m_listEntities.at(m_listEntities_selected[i]) ) > (m_listEntities.at(m_listEntities_selected.at(i))); // this is the error
*entity = *m_listEntities.at(m_listEntities_selected.at(i) );
entity->newPosition(point3d-point_base_copy);
m_listEntities.append(entity);
}
for(int i=0;i<m_listEntities_selected.size();i++)
{
BaseClass *entity = new BaseClass;
entity = dynamic_cast< typeid (m_listEntities.at(m_listEntities_selected[i]) ) > (m_listEntities.at(m_listEntities_selected.at(i))); // this is the error
*entity = *m_listEntities.at(m_listEntities_selected.at(i) );
entity->newPosition(point3d-point_base_copy);
m_listEntities.append(entity);
}
To copy to clipboard, switch view to plain text mode
I can solve my problem with a switch case, because I have virtual members in the derived classes that give a string with the type but that will be much less elegant and I will have to modify the switch case every time I create a new derived class. Any sugestion ?
Bookmarks