To get a compile-time error, you need a template:
template <int width, int height> class MatrixTemplate : public Matrix { static_assert(0 < width, "Invalid Width"); static_assert(0 < height, "Invalid Height"); public: MatrixTemplate() : Matrix(width, height) {} };
(Btw: I suggest unsigned types for indexes)
If you don't have static_assert (here I switch to unsigned):
template <unsigned width, unsigned height> class MatrixTemplate : public Matrix { public: MatrixTemplate() : Matrix(width, height) {} }; template <> class MatrixTemplate<0, 0> {}; template <unsigned height> class MatrixTemplate<0, height> {}; template <unsigned width> class MatrixTemplate<width, 0> {};
There is no support for empty matrices (MatrixTemplate <0, 0>). But it should be a simple task to set up static_asserts or the MatrixTemplate <0. 0> class.
Dieter lücking
source share