Monday, 9 September 2013

Inheritance, promote base class members

Inheritance, promote base class members

Given the following classes:
template <typename DataType, size_t Dimensions>
class Vector : public std::array<DataType, Dimensions> {
//stuff
};
template <typename DataType>
class Vector2 : public Vector<DataType, 2> {
//2d specific stuff
};
template <typename DataType, size_t Dimensions>
class Line {
public:
Vector<DataType, Dimensions>& min();
Vector<DataType, Dimensions>& max();
private:
Vector<DataType, Dimensions> m_min;
Vector<DataType, Dimensions> m_max;
};
template <typename DataType>
class Line2 : public Line<DataType, 2> {
//2d specific stuff
};
What's the best way to have min() and max() when called on a Line2, return
a Vector2& rather than a Vector&? Can I promote m_min and m_max to Vector2
within Line2? Or otherwise override them and still have the Line base
class function properly?

No comments:

Post a Comment