erez0...@gmail.com wrote:
hello,
i am trying to write a matrix class for linear algebra.
template <class T,int ROWS,int COLS> class matrix
{
private:
T m_data[COLS*ROWS];
public:
T &operator at(int x,int y) { ...}
....
};
I want to add a special function only to matrix<T,3,3>.
i still want it to inherent everything from the initial "matrix"
class.
if i just specialize it, i.e.
template <class T> matrix<T,3,3> {
public:
matrix<T,3,3> inv(void) {.....};
};
then i will only have inv(), but not everything else ( e.g. at()
function)
if on the other hand i do:
template <class T> matrix<T,3,3> : public matrix<T,3,3>
then i get a recursion ...
how do i solve that ?
There are two ways to achieve this really:
The usual solution is inheritance when inv() must be a member function,
so you could put your at() function in another class called MatrixBase
or something like that and then have your Matrix inherit that.
Your default Matrix might add nothing over MatrixBase, but
specialisations of it could add other things such as inv().
Alternatively if inv() can be implemented as a free function using the
public interface of Matrix then this might be a good approach also.
Alan
thanks, i'll try that.
sorry, there is no operator at (AFAIK).