Reputation: 541
I wrote template which return matrix in Window Form Application .My template is below:
template<class T>
class matrix1 {
protected:
public:
T *data;
const unsigned rows, cols, size;
matrix1(unsigned r, unsigned c) : rows(r), cols(c), size(r*c) {
data = new T[size];
}
~matrix1() { delete data; }
void setValue(unsigned row, unsigned col, T value) {
data[(row*cols)+col] = value;
}
T getValue(unsigned row, unsigned col) const {
return data[(row*cols)+col];
}
I wrote this code in Main Project File in Windows Form Application.I defined 341*680 matrix with using this template :
matrix1<double>A(341,680);
I used function that do operation on this template and I defined it like this:
void function(matrix1<double> &b,array< double>^ data)
And call it:
function(A,data);
(data is one dimensinonal data array that I have to use for my programming algorithm)
For Example;When I want to print data that is located in the first row and first column.
Visual C++ recognise getvalue and setvalue
function ,but couldn't print anything and gave a lot of error interested with matrix1 template
I tried this template and function on CLR Console Application and it worked.How could I do this On Windows Form Application.And Where should I locate template class on Windows Form Application.
Best Regards...
Upvotes: 0
Views: 236
Reputation: 7248
First of all you have a bug in the destructor, it should be
~matrix1() { delete []data; }
Upvotes: 1