//vector class declarations
template <class T>
class vec {
private:
int length;
T *v;
public:
vec();
explicit vec(int n);
vec(const T &a, int n);
vec(const T *a, int n);
vec(const vec &rhs);
vec & operator=(const vec &rhs);
vec & operator=(const T &a);
booloperator==(const vec &rhs);
inline T & operator[](constint i);
friend ostream & operator<< <>(ostream &s, vec &rhs);
inlineconst T & operator[](constint i) const;
inlineint size() const;
inlinebool isempty() const;
vec<int> find(const T &a);
~vec();
};
//matrix class declarations
template <class T>
class mat {
private:
int r;
int c;
T **v;
public:
mat();
mat(int n, int m);
mat(const T &a, int n, int m);
mat(const T *a, int n, int m);
mat(const mat &rhs);
mat & operator=(const mat &rhs);
mat & operator=(const T &a);
inline T* operator[](constint i);
friend ostream & operator<< <>(ostream &s, mat &rhs);
inlineconst T* operator[](constint i) const;
inlineint n_rows() const;
inlineint n_cols() const;
inlinebool isempty() const;
mat<int> find(const T &a);
int perimeter(const T &a);
~mat();
};
If you see the matrix class, I have a member function int perimeter(const T &a) . For my problem, the matrix typically represents an AREA (or region) on a grid. An area contains several PATCHES. Each patch may contain one or more CELLS. Therefore, the [i][j] index of matrix typically contains a number denoting the patch it belongs to. I would like to get the perimeter of a certain patch in the matrix and so I have implemented this member function.
However I would like to know if this is good organization or there are some other ways to implement USER-SPECIFIC operations of a DEFAULT/BASIC matrix class. Because, as you can see this has really nothing to do with the matrix class. Should I rather go about for example creating function templates for such specific operations or inherit this base class and then construct more sophisticated functions etc... Does my question make sense?
I think you've realised instinctively that pereimter doesn't belong there. And I'll confess that I don't know what all these methods do, but I agree that the applications of the matrix shouldn't be part of the matrix class.
My thinking is that if you can implement a shape's footprint using your matrix If done nicely, there'll be no runtime cost, and you'll have a more general matrix class.