Есть 2 класса:
class A
{
private:
double a1, a2;
...
};
class B : public A
{
private:
double b1, b2;
};
и универсальный контейнер
template <typename Item>
struct TList
{
typedef std::vector <Item> Type;
};
template <typename Item>
class GList
{
private:
typename TList <Item>::Type items;
};
Там 4 контейнера объектов
GList <A> A1;
GList <B> B1;
GList <A*> A2;
GList <B*> B2;
Разрешены или нет эти преобразования (вверх / вниз):
1] GList <B> B3 = dynamic_cast <GList <B> &> (A1);
2] GList <A> A3 = static_cast <GList <A> &> (B1);
3] GList <B*> B4 = dynamic_cast <GList <B*> &> (A2);
4] GList <A*> A4 = static_cast <GList <A*> &> (B2);
Есть ли способ как преобразовать список объектов в список родительских объектов и наоборот?
Обновленный вопрос
А как насчет reinterpret_cast?
1] GList <B> B3 = reinterpret_cast <GList <B> &> (A1);
2] GList <A> A3 = reinterpret_cast <GList <A> &> (B1);
3] GList <B*> B4 = reinterpret_cast <GList <B*> &> (A2);
4] GList <A*> A4 = reinterpret_cast <GList <A*> &> (B2);