dシミュレーションをプログラミングしています。これで、2Dと3Dの両方で機能するはずなので、クラスを2Dと3Dのベクトルで機能させようとしています。また、Vectorsには、座標に使用するタイプを示すテンプレートパラメータが必要です。
私の基本クラスは次のようになります。
class SimulationObject {
AbstractVector<int>* position;
AbstractVector<float>* direction;
}
問題は、ポリモーフィズムを使用できないことです。これは、すべてのベクトルがポインターである必要があり、これにより、次のような操作で演算子のオーバーロードがほぼ不可能になるためです。
AbstractVector<float>* difference = A.position - (B.position + B.direction) + A.direction;
ただし、テンプレートパラメータを使用して、使用するタイプを指定することもできません。
template <typename T> class Vector2d;
template <typename T> class Vector3d;
template <class VectorType> class SimulationObject {
VectorType<int> position;
VectorType<float> direction;
}
SimulationObject<Vector2D> bla;
//fails, expects SimulationObject< Vector2D<int> > for example.
//But I don't want to allow to specify
//the numbertype from outside of the SimulationObject class
それで、何をしますか?