Node Matrix class

I am constructing a Node Matrix class, that is, for general purpose. To consider each point in the matrix instead as a pixel, now I want to consider every point as a Node with some properties.

I create the Node with Matrix A(SIZE,SIZE) and here I want the initialization to begin. How should i store the nodes in the matrix?
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
Matrix::Matrix(unsigned &sizex, unsigned &sizey)
{
rows_ = sizey;
columns_ = sizex;
//Here I want to initialize some array with the nodes or something!?
//array = new Node[sizex*sizey];
//I want the array to store pointers to Node

}

class Matrix {
public:
	Matrix(unsigned &rows, unsigned &cols);
	void setSize(int &size);
//	double& operator() (unsigned row, unsigned col);      
//	double  operator() (unsigned row, unsigned col) const; 
	~Matrix();                              // Destructor
	Matrix();
	friend	ostream& operator<<(ostream& out, Matrix &m);
	
	unsigned getXDimensions();
	unsigned getYDimensions();
	
	Node* operator()(unsigned &row, unsigned &col);
	Node* operator()(unsigned row, unsigned col);

private:
	unsigned rows_, cols_;
	double* data_;
int size;
	//vector<int*> neighbors;
	Node* array[size];
	
};


In the pixel (double/integer) case. I could only use the data pointer to:
data_ = new double[sizex*sizey]; and it will create a array of that size. Then I can use data_[sizey-1+rows*(sizex-1)] to get specific value at specific point.
Do I need to overload the operator[] to use it with the node case?
I want to do following:

1
2
3
4
5
Matrix A(SIZE, SIZE);
for (y=0; y<SIZE; y++) {
for (x=0; x<SIZE; x++) {
A(i,j)->grayscaleValue = some value;  //where grayscalevalue is a double in the Node class A is containing Node*
}}

I get some errors now of course when I do not have any storage for the Node *p variables in the matrix. Somone that does have a clue how I should solve this?
Last edited on
If you are looking to do a general-purpose Matrix class, then you need to use
templates. Are you familiar with them?
Yes! But only so general that I can create and use a matrix with Node* ;) Of course it's nice to have several possibilities, but its not needed. So it can't be done without templates?
Topic archived. No new replies allowed.