c++ organization question

Hi,
I have already designed two classes with templates for "Vectors" and "Matrices" as follows (just the outline is shown below):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//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);
	bool operator==(const vec &rhs);
	inline T & operator[](const int i);
        friend ostream & operator<< <>(ostream &s, vec &rhs);
	inline const T & operator[](const int i) const;
	inline int size() const;
	inline bool 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[](const int i);
	friend ostream & operator<< <>(ostream &s, mat &rhs);
	inline const T* operator[](const int i) const;
	inline int n_rows() const;
	inline int n_cols() const;
	inline bool 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.
kbw wrote:
My thinking is that if you can implement a shape's footprint using your matrix


Pardon me, I don't understand what you mean by this...

The shape you see on a grid has just been rendered there, the shape (class) is more abstract.

Still don't get it? What if you needed to rotate it? The shape is just rendered on a grid in the same way it's rendered on a screen or printer.

If you seperate your grid class from the shape that's being rendered, you get a much more flexible representation.
Topic archived. No new replies allowed.