クラス PointsList の 1 つのオブジェクトを別のオブジェクト 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 オブジェクトへのポインターを表します。この場合のデータモデルは変更できません...