Я хотел бы привести один объект класса PointsList к другому объекту Points3DList (и наоборот), где:
template <class T>
class PointsList
{
protected:
std::vector <Point <T> *> points; //Only illustration, not possible with templaes
};
и
template <class T>
class Points3DList
{
protected:
std::vector <Point3D<T> *> points; //Only illustration, not possible with templaes
};
Между Point и Point3D естьнет связи (наследование или композиция) ...
template <class T>
class Point
{
protected:
T x;
T y;
public:
Point( const T &x_, const T &y_ ) : x ( x_ ), y ( y_ ) {}
inline T getX() const {return x;}
inline T getY() const {return y;}
inline void setX ( const T &x_ ) {x = x_;}
inline void setY ( const T &y_ ) {y = y_;}
....
};
template <class T>
class Point3D
{
protected:
T x;
T y;
T z;
};
Что вы думаете о преобразовании
Points3DList <T> *pl3D = new Points3DList <T> ();
...
PointsList <T> *pl = reinterpret_cast < PointList <T> * > ( pl3D );
, где pl3D представляет указатель на объект Points3DList. Может ли в этом случае использоваться reinterpret_castили лучше создать функцию преобразования?Модель данных в этом случае не может быть изменена ...